shahin
Active Member
Can't incorporate an idea frequenting in my mind. While working with python I noticed that there is a rarely used method applied when it comes to run loops. However, the method is, if a loop starts from 1 then it will run until the "http.status=404", which indicates that a loop will run until it finds the url with the looping number in it which doesn't exist and the code will break. I don't know whether it is applicable in vba. Took a chance, though! Tried initially with:
Code:
Sub movie_name()
Const mlink = "https://www.yify-torrent.org/genres/western/"
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim post As Object
With http
.Open "GET", mlink, False
.send
html.body.innerHTML = .responseText
End With
For y = 1 To http.Status <> 200
With http
.Open "GET", mlink & "p-" & y & "/", False
.send
html.body.innerHTML = .responseText
End With
For Each post In html.getElementsByClassName("mv")
With post.getElementsByTagName("h3")
x = x + 1
If .Length Then Cells(x, 1) = .Item(0).innerText
End With
Next post
Next y
End Sub