Text from website to a string

ssdzkrez

Member
Hello friends!

I'm a beaginer with b4a, soo ... :) I would like to read 2 simple text lines between <div id> from the website to a string ... "text1, text2". Is there any simple way to do this?

Website code:
Code: Copy
<div id = "temp">TextToRead1</div>
<div id = "temp1">TextToRead2</div>
 
Try something like this to read the content of your html page:

Code: Copy
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim job1T As HttpJob
    Dim htmlpage as String
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    job1T.Initialize("job1T", Me)
    job1T.Download("http://www.MySite.com/MyPage.html")
End Sub

Sub JobDone(Job As HttpJob)
    If Job.Success = True Then
        htmlpage = Job.GetString
    End If
End Sub

Then, you should parse htmlpage to extract your values.
 
Upvote 0
Thx for fast replay. I'm looking a simple solution to read text only between a certain <div id>, not to store the whole website. Is that possible?
 
Upvote 0
Hello ssdzkrez,

KPmaster has actually given you the answer you require. You are not downloading the whole website, just one page.

Have a look at the Flickr Viewer from Erel (especially the sub: HandleMainPage). It is easy to understand and you will be able to modify it.

Link: http://www.b4x.com/android/forum/threads/flickr-viewer.6646/

A Regex tester you can find here http://regexpal.com/

Otherwise ask....

Best regards
 
Upvote 0
Maybe this is a too hard job for beginner like me. I looked all the links above, I tried to write some code, but I do not get anywhere. Can you guys give me an example how to parse "htmlpage" to extract those 2 text lines?

THX!
 
Upvote 0
Back
Top