Can't use querySelector in the right way in vba

前端 未结 4 777
醉酒成梦
醉酒成梦 2021-01-14 21:48

I\'ve written some code using vba to get all the movie names from a specific webpage out of a torrent site. However, pressing \"F8\" I could find out that the code works wel

4条回答
  •  -上瘾入骨i
    2021-01-14 22:48

    looks like querySelectorAll has an issue of some sort

    the object html.querySelectorAll(".mv h3 a") cannot be examined in Watch window.

    attempting to do so crashes excel or word (i tried both)

    tried other tags, same result

    Sub Torrent_data()
    
        Dim http As New XMLHTTP60, html As New HTMLDocument
        Dim movie_name As Object, movie As Object
    
        With http
            .Open "GET", "https://www.yify-torrent.org/search/1080p/", False
            .send
            html.body.innerHTML = .responseText
        End With
    
    '   Set movie_name = html.querySelectorAll("div.mv h3 a")   ' querySelectorAll crashes VBA when trying to examine movie_name object
    
        Set movie_name = html.getElementsByClassName("mv")      ' HTMLElementCollection
    
        For Each movie In movie_name
            x = x + 1: Cells(x, 1) = movie.getElementsByTagName("a")(1).innerText
        Next movie
    
    '   HTML block for each movie looks like this
    
    '   
    '

    ' Smoke (1995) 1080p '

    ' '
    '
      '
    • Genre:Comedy
    • Quality:1080p
    • Screen:1920x1040
    • Size:2.14G
    • Rating:7.4/10
    • Peers:2
    • Seeds:0
    • '
    ' Download '
    '
    End Sub

提交回复
热议问题