Tips for fully accessing a website with javascript enabled through an android service

I've been attempting to extract data from a website node that includes JavaScript. In VB .NET, the code I typically use is as follows:

Dim listSpan As IHTMLElementCollection = bodyel.getElementsByTagName("span")

For Each spanItem As IHTMLElement In listSpan
    If spanItem.className & "" = "span_name" Then
        If Not spanItem.innerText Is Nothing Then
            str_result = spanItem.innerText.ToString
            Console.WriteLine("Found it: " & str_result)
        Else
            str_result = "NO"
            Console.WriteLine("Not Found")
            Console.Beep(500, 500)
        End If
    End If
Next

However, I am struggling to adapt this code to function within an Android service (Java).

I experimented with Jsoup, but it only captures the elements in the "view source code" and not the JavaScript-generated content in HTML.

try {
    Document doc = Jsoup.connect(str_link).get();               
    Elements links = doc.select("span_name");

    for(Element link : links) {
        String result = link.text();  
        Log.d("TMA Service","result: " + result);
        list.add(title);
    }
}

Basically, the VB code is able to uncover all the information similar to when right-clicking on an element in Google Chrome and choosing "Inspect Element." This reveals everything, and I am looking for a way to access this data via Android.

Could someone provide me with an example?

Thank you.

Answer №1

It seems that handling Javascript and dynamic content with Jsoup is not possible. To explore alternative solutions and Java libraries that may assist you, please refer to my answer here.


Edit:

  • HtmlUnit - Getting started (section Getting started)
  • HtmlUnit: A Simple Example: Check Yahoo Email
  • How to use HtmlUnit in Java?
  • HtmlUnit: A Quick Introduction
  • HtmlUnit – A quick introduction
  • Getting started with HtmlUnit

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Instructions for transferring numerous chosen files (such as .doc, .pdf, .jpeg, .png) to a server from an Android device

Can you provide guidance on selecting multiple files from a file manager in Android? Once the details of the image are displayed (such as image size, name, and the option to delete the files), how can we upload these files to a server? ...

JQuery WCF Service is returning a 400 Bad Request response

I developed a WCF web service in ASP.NET 4.5 using VS2012 that delivers a JSON response successfully via the built-in webservice client. The endpoints are correctly configured in the Web.config file. However, I encountered an issue on the client side with ...

Unable to retrieve location information from Google Maps

I attempted to retrieve location details such as locality, country, and postal code from Google Maps using latitude and longitude coordinates. Unfortunately, the code I used resulted in null data: Edit: public void onLocationChanged(Location location) { ...

Provide props to vue-router along with boostrap-vue's b-nav-item

I am currently in the process of transitioning my SPA from modals that load components to routed pages that load components. I have been able to successfully open a page using to="/fixtures" in the html, but I am facing an issue with passing in a component ...

An error occurred: [object Object] does not contain the function 'bootstrapDatepicker'

After spending countless hours searching for a solution, I continue to encounter the dreaded 'Uncaught TypeError' without any successful resolutions. The issue seems to stem from a clash between tribe-events-ajax-calendar.js and foundation.min.j ...

JavaScript file does not execute onload function

Whenever I try to execute the window.onload function from my .js file, it seems to not be firing as expected. <script type="text/javascript" src="{% static 'jsfile.js' %}"></script> window.onload = function() { alert(' ...

Explore three stylish ways to showcase dynamic JavaScript content using CSS

Objective: For Value 1, the CSS class should be badge-primary For Value 2, the CSS class should be badge-secondary For all other values, use the CSS class badge-danger This functionality is implemented in the handleChange function. Issue: Current ...

The search function for selecting plugins is not functioning properly when additional options are added

Is there a way to use select options with search functionality, but the options are appended? I've tried using plugins like tom-select, selectize, and chosen but none of them seem to work with the appended options. Can anyone provide assistance on how ...

What is the process for logging out when a different user signs in using Firebase authentication in a React Native application?

I am new to React Native and facing challenges with managing authentication state in my application. Currently, I am using Redux but have not yet implemented persistence for user login. I have incorporated Firebase authentication. Essentially, I would li ...

JS problem with using for and foreach loops in Node.js

I've been really stumped by this situation. Everything was running smoothly until 4 days ago when two of my cron daemon jobs suddenly stopped working. Instead of ignoring the issue, I decided to take the opportunity to rebuild and enhance the code. I ...

What is the process for creating an audio file by combining N audio samples with specific time gaps between each one?

I am currently developing an Android application that features a Drum Kit simulation where users can record their performances. The recordings are stored in a .json file, capturing the audio sample played and the time interval between each note. Here is a ...

How should post comments be stored effectively in Firebase?

Currently, I am in the process of developing an app utilizing Firebase with a classic blog format as its foundation. This application will consist of properties (similar to posts), users, and comments associated with each property. I am deliberating on w ...

Identify the class within a child division and include the class in a separate division

How can I detect a special class within a child div and then add a class to another div when that specific class is found? For example: <ul class="m-a-ul"> <li class="menu"> </ul> Now, if the class collapsed is dynamically added: ...

Learn how to use a function in Google Maps to calculate and display distances

I have a script obtained from this link here and I am trying to create a function that returns the distance. This is my current script: var calcRoute = function(origin, destination) { var dist; var directionsDisplay; var directionsService = ne ...

What is the best way to retrieve a value from a promise in JavaScript?

As someone who is relatively new to working with promises, I find myself in a bit of a sticky situation. Despite reading several articles and Stack Overflow posts on the topic, I still can't seem to fully grasp it. My dilemma involves a simple API th ...

Guide on duplicating text and line breaks in JavaScript

There is some text that looks like this text = 'line 1' + "\r\n"; text+= 'line 2' + "\r\n"; text+= 'line 3' + "\r\n"; I have developed a function to help facilitate copying it to the clipboard ...

Instructions for activating the "Navigate to Declaration" feature in TypeScript for JSON files using i18next

Currently, I am actively engaged in a project that involves the use of i18next with react and typescript. In this project, translation keys are defined within .json files. However, a notable drawback of transitioning to json for the translation files is l ...

The image fails to appear while creating a PDF in AngularJS using pdfmake

I recently started using a fantastic pdf printing library called pdfmake in my angularjs SPA to generate PDF files. Everything was going smoothly until I tried to include images in the PDF. Strangely, when I added images, nothing happened - no errors, no e ...

The chatbot text input feature is malfunctioning and failing to display the entered text in the chatbox

Hi there! I'm in the process of creating a chatbot using a basic input text box and button in HTML, with a php start function. Unfortunately, when I enter text into the textbox, nothing is showing up on the screen and the button doesn't seem to b ...

How do I assign a default value to an optional parameter in a derived class in Typescript?

One of my classes is called ClientBase: export class ClientBase { constructor(private uri: string, private httpClient: HttpClient) { } // Contains Various Methods } I have multiple subclasses that are derived from the ClientBase For instance: @I ...