简体   繁体   中英

Web crawling Accuweather

I want to capture the current weather (88 in image)information from the website

Check the image

https://www.accuweather.com/en/in/bengaluru/204108/weather-forecast/204108

I have used the following code

Sub Get_Price()
Dim HTTP As New XMLHTTP60, HTML As New HTMLDocument
Dim post As HTMLDivElement

With HTTP
.Open "GET", "https://www.accuweather.com/en/in/india-weather", False
.send
HTML.body.innerHTML = .responseText
MsgBox .responseText
End With

For Each post In HTML.getElementsByClassName("panel-list cityforecast")
With post.getElementsByTagName("large-temp")
 If .Length Then R = R + 1: Cells(R, 1) = .Item(0).innerText
End With
Next post
End Sub

Please help, Thanks in advance

Try the below approach to get the information you would like to parse from that page. I used .querySelectorAll() within the script to make it concise but more effective. Give it a shot.

Sub GetWeatherInfo()
    Dim HTTP As New XMLHTTP60, HTML As New HTMLDocument
    Dim post As Object

    With HTTP
        .Open "GET", "https://www.accuweather.com/en/in/bengaluru/204108/weather-forecast/204108", False
        .send
        HTML.body.innerHTML = .responseText
    End With

    Set post = HTML.querySelectorAll("#feed-tabs .large-temp")(0)
    MsgBox post.innerText
End Sub

Reference to add to the library:

Microsoft XML, V6.0 ''or the version you have
Microsoft HTML Object Library

Btw, before running the script, make sure the url I used is the right one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM