shahin2137
New Member
- Joined
- Feb 11, 2017
- Messages
- 1
I have made a scraper using vba xmhttp method which is parsing yell.com very smoothly at this moment.However, I noticed that the site sometimes uses a redirection method.As a result I end up with nothing returned when I run the code.So if there is somebody out here that can help me create this same code using winhttp method I would really appreciate it.I have never worked with this method before and that is why it is totally foreign to me.For your consideration I am pasting the code I have written.
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Option Explicit
Const pageurl As String = "https://www.yell.com/ucs/UcsSearchAction.do?keywords=cafes+%26+coffee+shops&location=all+states&scrambleSeed=1864223494&pageNum="
Sub ScrapingYell()
Dim http As New MSXML2.XMLHTTP60
Dim html As New HTMLDocument
Dim posts As Object, post As Object, links As Object, link As Object
Dim x As Long, u As Long
x = 2
For u = 2 To 6
http.Open "GET", pageurl & u, False
http.send
html.body.innerHTML = http.responseText
Set posts = html.getElementsByClassName("row businessCapsule--title")
For Each post In posts
Set links = post.getElementsByTagName("a")(0)
Cells(x, 1) = links.innerText
x = x + 1
Next post
Next u
End Sub</code>
<code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; white-space: inherit;">Option Explicit
Const pageurl As String = "https://www.yell.com/ucs/UcsSearchAction.do?keywords=cafes+%26+coffee+shops&location=all+states&scrambleSeed=1864223494&pageNum="
Sub ScrapingYell()
Dim http As New MSXML2.XMLHTTP60
Dim html As New HTMLDocument
Dim posts As Object, post As Object, links As Object, link As Object
Dim x As Long, u As Long
x = 2
For u = 2 To 6
http.Open "GET", pageurl & u, False
http.send
html.body.innerHTML = http.responseText
Set posts = html.getElementsByClassName("row businessCapsule--title")
For Each post In posts
Set links = post.getElementsByTagName("a")(0)
Cells(x, 1) = links.innerText
x = x + 1
Next post
Next u
End Sub</code>