shahin
Active Member
I've written some code to experiment how conditional statement works when I apply it on a webpage to parse a certain item from. I used if statement in two different ways in my script. The one brings messy text is commented out in my script. If more accurately described then the commented out "If statement with Instr() function" is fetching a whole bunch of junk along with the one I'm after. However, the uncommented if statement is working just fine but it is seriously fragile because when my search becomes "R016698 " (mark the ending space) instead of "R016698" It fails to catch that. Why my commented out "If statement" is not working as I expected (I meant to get the exact value and nothing else) and how to fix that? I hope I could make my description clear. Any help would be much appreciated.
Here is the code:
The result I get using uncommented "If statement":
The result I get using commented out "If statement with Instr() function" is huge which I have attached in a text file below.
Here is the code:
Code:
Sub Get_Page()
Dim IE As New InternetExplorer, html As HTMLDocument, post As Object
With IE
.Visible = True
.navigate "http://search.wcad.org/Property-Search-Result?searchtext=319%20lizzie%20taylor"
Do Until .readyState = READYSTATE_COMPLETE: Loop
Set html = .document
End With
Application.Wait Now + TimeValue("0:00:05")
For Each post In html.getElementsByTagName("td")
''If InStr(post.innerText, "R016698") > 0 Then [A1] = post.innerText: Exit For
If post.innerText = "R016698" Then [A1] = post.innerText: Exit For
Next post
IE.Quit
End Sub
The result I get using uncommented "If statement":
Code:
R016698
The result I get using commented out "If statement with Instr() function" is huge which I have attached in a text file below.
Attachments
Last edited:
