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:
B4X:
<div id = "temp">TextToRead1</div>
<div id = "temp1">TextToRead2</div>
Try something like this to read the content of your html page:
B4X:
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.
You have two options. You can manually parse the text (preferably with Regex) or you can use JTidy library to convert the Html to XML and then parse it with an XML parser.
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?