Safe way to web scrape within VBA

Viewed 40

I need to scrape some price data from a website. To get this done, I use the following snippet:

With http
    .Open "GET", url, False
    .send
    html.body.innerHTML = .responseText
End With
Set topics = html.getElementsByClassName("sidebar-item-label")

    For i = 1 To topics.Length - 1
    str = topics(i).href

It works, but I am wondering how to secure the data, before assigning the html response to my variable str. To avoid malicious code get run on my windows machine, I need to validate, sanatize and escape the response data, before safe it to the variable and do the further stuff like string splitting and save it into my Excel spreadsheet.

Does anybody can help me with that? Do you need more informations?

1 Answers

My code so far:

Dim objXmlHTTP as New XMLHTTP60, html as New HTMLDocument
Dim prices as IHTMLElementCollection

With objXmlHTTP
     .open "GET", URL, FALSE
     .send
     html.body.innerHTML = .responseText
End With

Set prices = html.getElementsByClassName("MyClass")

After getting the data, I am looping through the collection and search for a specific string "price" and assign the data t/value of price to an Excel cell. So and to avoid that excel will execute any bad code, I want to validate, sanatize and escape the data, before saving the html data into Excel cell.

Related