• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Unable to parse a value without hardcoding index

shahin

Active Member
I've written a macro to pull some information from a webpage. When i run the macro, it populates a result which is br/newline separated string. I would like to get the last portion of that string. Currently what I'm doing is able to fetch me the last value which is phone number. However, i would like to avoid this hardcoding index "(5)" to get the value. If i knew how to count things in the reverse way then I could do it myself because the value i'm after is exactly located in the last position. However, any help on is would be highly appreciated.

This is what I tried with:
Code:
Sub Data_scraper()
    Dim IE As New InternetExplorer
    Dim ieDoc As HTMLDocument

    With IE
        .Visible = False
        .navigate "http://www.retailbusinesstechnologyexpo.com/exhibitor-profile/citizen-systems-europe"
        Do Until .readyState = 4: DoEvents: Loop
        Set ieDoc = .document
        MsgBox ieDoc.getElementsByClassName("editorLabel")(0).innerText
'        MsgBox Split(ieDoc.getElementsByClassName("editorLabel")(0).innerText, vbNewLine)(5)
    End With
    IE.Quit
End Sub

The result it produces:

Code:
"Citizen Systems Europe
Elizabeth House
56-60 London Road
Staines-Upon-Thames
TW18 4HF
Tel. 0208 893 1900"

If you run the macro after uncommenting the line then you will find that my script can parse only the phone number. I just wish to do the same without using hardcoding index like what i did. Because, if the string contains more information then the position of that phone number could be 7, 8, 9 whatever and my script will fail to scrape that. But if i continue with the last index without hardcoding then i will always get the accurate result i'm after.
 
HI Shahin,

Try the array to get the last index.
Code:
Sub Data_scraper()
    Dim IE As New InternetExplorer
    Dim ieDoc As HTMLDocument
Dim wdArray() As String
    With IE
        .Visible = False
        .navigate "http://www.retailbusinesstechnologyexpo.com/exhibitor-profile/citizen-systems-europe"
        Do Until .readyState = 4: DoEvents: Loop
        Set ieDoc = .document
       ' MsgBox ieDoc.getElementsByClassName("editorLabel")(0).innerText
        'MsgBox Split(ieDoc.getElementsByClassName("editorLabel")(0).innerText, vbNewLine)(5)
        'MsgBox Split(ieDoc.getElementsByClassName("editorLabel")(0).innerText, vbNewLine)(5)
        wdArray = Split(ieDoc.getElementsByClassName("editorLabel")(0).innerText, vbNewLine)
        MsgBox wdArray(UBound(wdArray))
   End With
    IE.Quit
End Sub
 
@sir chihiro, yes it is. You explained very clearly about ubound in that thread. However, The usage of ubound didn't come to my mind in this case.
 
Back
Top