• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Working with ".queryselectorAll()"

shahin

Active Member
After several trials and errors using ".queryselectorAll()", I could come up with an excellent solution that will exactly play the role like "for loop" does. I used "with block" instead of for loop to serve the purpose and it does the trick flawlessly. Thanks to Marc L, for teaching me the usage of "with block". Here is how I tried and got success:

Code:
Sub Torrent_Data()
    Dim IE As New InternetExplorer, HTML As HTMLDocument
    Dim post As Object

    With IE
        .Visible = False
        .navigate "https://yts.am/browse-movies"
        Do While .readyState <> READYSTATE_COMPLETE: Loop
        Set HTML = .document
    End With

    With HTML.querySelectorAll(".browse-movie-bottom")
        For I = 0 To .Length - 1
            Cells(I + 1, 1) = .Item(I).querySelector(".browse-movie-title").innerText
            Cells(I + 1, 2) = .Item(I).querySelector(".browse-movie-year").innerText
        Next I
    End With

    IE.Quit
End Sub
 
Or without using any variable as object:
Code:
Sub Torrent_Data()

    With CreateObject("InternetExplorer.Application")
        .Visible = False
        .navigate "https://yts.am/browse-movies"
        While .Busy = True Or .readyState < 4: DoEvents: Wend

        With .document.querySelectorAll(".browse-movie-bottom")
            For I = 0 To .Length - 1
                Cells(I + 1, 1) = .Item(I).querySelector(".browse-movie-title").innerText
                Cells(I + 1, 2) = .Item(I).querySelector(".browse-movie-year").innerText
            Next I
        End With
    End With
   
End Sub
 
Back
Top