0

I'm trying to read a node from a website that contains java script.

In VB .NET I just use the following code:

            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

But I just can't find a way to convert this code to work in Android service. (Java).

I tried Jsoup but Jsoup is only reading the "view source code" elements and not the javascript results as 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);

}

I mean. This code in VB can find everything. (just like if I right click in an element using google chrome and select "Inspect Element". This shows everything and I'd like to know how to get this data with Android.

CAN SOME ONE GIVE ME AN EXAMPLE?

Thanks.

Totalys
  • 445
  • 2
  • 10
  • 25

1 Answers1

1

Unfortunately you can't handle Javascript and dynamic content with Jsoup. Please see my answer here for more information and some examples of Java libraries, that may help you here.


Edit:

Community
  • 1
  • 1
ollo
  • 24,797
  • 14
  • 106
  • 155
  • Do you have some working example please? I ran through HTMLUnit but I failed completely... – Totalys Feb 16 '14 at 01:20
  • I've added some links to tutorials and examples, i hope they can help you. – ollo Feb 16 '14 at 23:34
  • 1
    Thanks @ollo. But I read these tutorial but after implementing their guidelines I got stuked at this situation: [stack Overflow question about htmlUnit in Android - not resolved](http://stackoverflow.com/questions/8282259/htmlunit-on-android-application) – Totalys Feb 17 '14 at 00:08
  • I see … have you tried the suggestions in the answers and searched in the internet? – ollo Feb 17 '14 at 15:01
  • Yes. @ollo. I'm stuked on that for 15 days... and I just can't make it work :( – Totalys Feb 18 '14 at 01:20
  • I have one more Link for you: http://stackoverflow.com/questions/14885422/how-to-use-htmlunit-with-my-android-project. I hope this helps you a bit. – ollo Feb 19 '14 at 22:14
  • Please do not use HtmlUnit for Android. Its numerous JAR's are simply too large in size to be able to be ported into an Android app. Your IDE will crash if you attempt to run your app. – Tanuj Nayak Jun 27 '14 at 08:10