shahin
Active Member
As a vba beginner sometimes i find it hard to understand how function works. If you consider the below example then you can see that the first scraper is running flawlessly. However, when I make my scraper act like same in case it is wrapped within a function, it works no more. It is happening only because i could not propel it the right way. How can i execute my second scraper?
First one (working):
Second one (not working):
First one (working):
Code:
Sub WebData()
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim source As Object
With http
.Open "GET", "http://www.brazil4export.com/en/pesquisa/resultado/?page=1&", False
.send
html.body.innerHTML = .responseText
End With
For Each source In html.getElementsByClassName("panel-heading")
x = x + 1: Cells(x, 1) = source.getAttribute("data-Name")
Cells(x, 2) = source.getAttribute("data-site")
Next source
End Sub
Second one (not working):
Code:
Function GetResult(url As String) As String
Dim http As New XMLHTTP60, html As New HTMLDocument
With http
.Open "GET", url, False
.send
html.body.innerHTML = .responseText
End With
GetResult = html.body.innerHTML
End Function
Sub Test_result()
Dim source As Object
GetResult ("http://www.brazil4export.com/en/pesquisa/resultado/?page=1&")
For Each source In (what should be here?).getElementsByClassName("panel-heading")
x = x + 1: Cells(x, 1) = source.getAttribute("data-Name")
Cells(x, 2) = source.getAttribute("data-site")
Next source
End Sub
Last edited: