shahin
Active Member
Few days back when I insisted a lot to Marc L on creating me a recursive crawler in vba, he provided me with an effective one. I modified that piece of code to apply on another website to scrape all the movie names traversing multiple pages (3 pages long here). It is just working great. However, this time I would like to do the same without creating two subroutines. As you can see (if you take a look at the below scraper), I've used two subroutines to accomplish the task.
This is the scraper which parses the site recursively:
Once again, my goal is to create one subroutine and still it will parse the data recursively.
This is the scraper which parses the site recursively:
Code:
Sub Get_Info(link As String)
Dim HTTP As New XMLHTTP60, HTML As New HTMLDocument
Dim posts As Object, post As Object, elem As Object
Dim URL As String, base As String, preff As String
base = "https://yts.am/browse-movies/0/all/biography/8/rating?page="
With HTTP
.Open "GET", link, False
.send
HTML.body.innerHTML = .responseText
End With
For Each post In HTML.getElementsByClassName("browse-movie-title")
Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = post.innerText
Next post
For Each elem In HTML.getElementsByClassName("tsc_pagination")(0).getElementsByTagName("a")
If InStr(elem.innerText, "Next") > 0 Then preff = Split(elem.href, "page=")(1): Exit For
Next elem
If preff <> "" Then
URL = base & preff
Get_Info (URL)
End If
End Sub
Sub RCrawler()
Get_Info "https://yts.am/browse-movies/0/all/biography/8/rating"
End Sub
Once again, my goal is to create one subroutine and still it will parse the data recursively.