Search code examples
htmlvbaweb-scrapingscreen-scraping

Web scraping without id VBA


I'm trying to scrape a web , some elements were easy to get . But I have a problem with those who have no id like this .

<TABLE class=DisplayMain1 cellSpacing=1 cellPadding=0><TBODY> <TR class=TitleLabelBig1> <TD class=Title1 colSpan=100><SPAN style="FONT-FAMILY: arial narrow; FONT-WEIGHT: normal">Tool &amp; </SPAN><BR>PE311934-1-1 </TD></TR></TBODY></TABLE>

i want this ---►PE311934-1-1

i Try with "document.getElementsByClassName" but the vba gave me a error :/..

some tip?


Solution

  • Use Regular Expressions and the XMLHttpRequest object in VBA

    I made a AddIn some time ago that does just that:

    http://www.analystcave.com/excel-tools/excel-scrape-html-add/

    If you just want the source code then here (GetElementByRegex function):

    http://www.analystcave.com/excel-scrape-html-element-id/

    Now the actual regex will be quite simple:

    </SPAN><BR>(.*?)</TD></TR></TBODY></TABLE>
    

    If it captures too much items simply expand the regex.