B4J Question Extract values from website

bdunkleysmith

Active Member
Licensed User
Longtime User
The attached project is a testbed I'm using for a project where I want to extract some values from a website. I have a fully working version in Visual Basic 2010 and a working testbed in B4A, but I just can't get the extraction working in B4J.

The code:

B4X:
    js.evalString("var x = doc.getElementById('aj_1_score');")
    js.evalString("var y = x.innerHTML;")
    js.evalString("var t = doc.title;")
    Msg.Show(js.engineGet("x"),"engineget_x")
    Msg.Show(js.engineGet("y"),"engineget_y")
    navBar.Text = js.engineGet("y")
    Msg.Show(js.engineGet("t"),"engineget_t")

returns:

[objectHTMLSpanElement]

[email protected]

[email protected]

I saw in another thread that the return of something like [email protected] was due to the page not being fully rendered, but this shouldn't be the problem given it's included in a PageFinished sub.

The code which works in B4A is:

B4X:
Sub WebView1_PageFinished (Url As String)
    '    Now that the web page has loaded we can get the data we want
  
    '    see the documentation http://www.basic4ppc.com/forum/additional-libraries-classes-official-updates/12453-webviewextras.html#post70053 for details of the second parameter callUIThread
  
    Dim Javascript As String
    For count = 1 To 2
        TeamScore = "aj_"&count&"_score"
        Javascript="B4A.CallSub('ProcessHTML', true, document.getElementById('"&TeamScore&"').innerHTML, '"&TeamScore&"')"

        'Log("PageFinished: "&Javascript)
        WebViewExtras1.executeJavascript(WebView1, Javascript)
  
    Next
  
End Sub

Sub ProcessHTML(Html As String, Team As String)
    '    This is the Sub that processes the extracted data
  
    'Log(Team & " = " & Html)
    Msgbox(Html,Team)
  
End Sub

Any assistance appreciated.
 

Attachments

  • WebViewTest.zip
    2.3 KB · Views: 326

bdunkleysmith

Active Member
Licensed User
Longtime User
Just a post to close this question out in case what I've found is useful to others.

I've been using JDK7, avoiding Java 8 because I wanted to retain compatibility with some XP machines I'd like the application to run on.

However, I installed the JDK8 on my Win7 laptop and I suppose not surprisingly it works as expected using the code shown at post #11, with the values being returned as real strings rather than things like [email protected]??????.

I suppose now I've just got to decide whether to develop the application within the limitations of JDK7 or accept that XP machines are really just boat anchors now and it can only be run on machines with Java8. It's actually the same thing I faced with the original VB version of the application as that now doesn't work on XP machines as the latest version of IE supported by XP doesn't display the target websites correctly.

Thanks to Erel, Daestrum and Jmon for your input.
 
Upvote 0
Top