【问题标题】:Web crawling Accuweather网络爬取Accuweather
【发布时间】:2018-10-12 12:32:48
【问题描述】:

我想从网站上捕捉当前天气(图像中的 88 天)信息

Check the image

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

我使用了以下代码

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

请帮忙,提前谢谢

【问题讨论】:

  • large-temp 似乎是类,而不是 tagNames。
  • AccuWeather 很可能禁止抓取他们的网站。获取 API 访问令牌并使用他们的 API。 (这也会更容易做到)。
  • 谢谢@Tomalak 有没有可能使用脚本爬取?
  • 你为什么会说“谢谢”然后又直接问你原来的问题?使用 API。
  • 目前还不清楚您想从该页面中抓取哪一部分信息。你能显示你想要的输出吗?顺便说一句,您在上面提供的链接和您在脚本中使用的链接不同。

标签: vba web-scraping web-crawler


【解决方案1】:

尝试以下方法从该页面获取您想要解析的信息。我在脚本中使用了.querySelectorAll(),以使其简洁但更有效。试一试。

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

添加到库的参考:

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

顺便说一句,在运行脚本之前,请确保我使用的 url 是正确的。

【讨论】:

  • 另外你能帮我如何获得这些知识吗?
  • 了解什么?如果您在谈论.queySelectorAll(),那么我已经提供了链接。但是,如果是关于网络抓取,那么this link 可能会有所帮助。谢谢。
  • 当然我会检查的。非常感谢您的帮助。谢谢
  • 你能帮我从下面的链接/accuweather.com/en/in/bengaluru/204108/month/204108?view=table删除表格吗
  • 创建一个描述您当前需求的新帖子并在此处放置一个链接。我会看看。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-15
  • 2020-01-18
  • 1970-01-01
相关资源
最近更新 更多