0

I've been struging since yesterday on how to do a "simple" task, that is to retrieve a WebPage's html source-code... From what I can see, with WebView its just not possible, so I should use http instead, but albeit all my efforts, no luck...

Can anyone post a simple example?

Thanks in advance

leppie
  • 115,091
  • 17
  • 196
  • 297
Cableguy
  • 1
  • 1
  • 1

3 Answers3

0

If you want the source HTML code for a page here are the steps for the most popular browsers:

Chrome - View -> Developer -> View Source

Safari - View -> View Source

Firefox - Tools -> Web Developer -> View Source

I'm not sure this is exactly what you're asking but if you just want to view the source of a page, then this is it.

ninu
  • 890
  • 2
  • 10
  • 26
  • Thanks for the answer, but I am trying to retrieve it programaticaly and parse it to a string so I can later extract pertinent data (Using Basi4Android of course) – Cableguy Oct 29 '11 at 18:38
0

I think you'll find what you're looking for here Link to B4A Forum post, you need to get the HTML to a string first, then load it to the web view with webview1.LoadHtml(s) (if you still want to). The first code example is enough for what you want.

You'll need to download the HttpUtilsExample.zip attached to the post and add the HttpUtils and HttpUtilsService modules to your project and enable the HTTP library.

Once you've got the modules in place the 'main' module should look like this:

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
  'MY ADDED LINE
  Dim Webview1 As WebView

  Dim b4a As String
  b4a = "http://www.basic4ppc.com"
End Sub

Sub Activity_Create (FirstTime As Boolean)

  'MY ADDED 2 LINES
  webView1.Initialize("Webview1")
  Activity.AddView(Webview1,0,0,100%x,100%y)

  HttpUtils.CallbackActivity = "Main" 'Current activity name.
  HttpUtils.CallbackJobDoneSub = "JobDone"
  HttpUtils.Download("Job1", b4a)
End Sub

Sub JobDone (Job As String)
 Dim s As String
 If HttpUtils.IsSuccess(b4a) Then
  s = HttpUtils.GetString(b4a)

  'MY ADDED 2 LINES
  Log(s)
  Webview1.LoadHtml(s)

 End If
End Sub
stevel05
  • 28
  • 5
0

If you have a webpage loaded in a WebView and want to get that loaded HTML then you can do so with the JSInterface library.

Take a look at my post in this thread for details:

http://www.basic4ppc.com/forum/basic4android-updates-questions/9400-save-webview-html-file-2.html#post56406

Martin Pearman
  • 592
  • 5
  • 5