gpt4 book ai didi

Rvest 无法识别 css 选择器

转载 作者:行者123 更新时间:2023-12-02 08:23:36 25 4
gpt4 key购买 nike

我正在尝试抓取这个网站:

http://www.racingpost.com/greyhounds/result_home.sd#resultDay=2015-12-26&meetingId=18&isFullMeeting=true

通过 R 中的 rvest 包。

不幸的是,rvest 似乎无法通过 CSS 选择器识别节点。

例如,如果我尝试提取每个表(等级、奖品、距离)的标题中的信息,其 CSS 选择器为“.black”,并且我运行此代码:

URL <- read_html("http://www.racingpost.com/greyhounds/result_home.sd#resultDay=2015-12-26&meetingId=18&isFullMeeting=true")
nodes<-html_nodes(URL, ".black")

nodes 结果是一个空列表,所以它没有抓取任何东西。

最佳答案

它发出 XHR 请求以生成 HTML。试试这个(这也应该更容易自动化数据捕获):

library(httr)
library(xml2)
library(rvest)

res <- GET("http://www.racingpost.com/greyhounds/result_by_meeting_full.sd",
query=list(r_date="2015-12-26",
meeting_id=18))

doc <- read_html(content(res, as="text"))

html_nodes(doc, ".black")
## {xml_nodeset (56)}
## [1] <span class="black">A9</span>
## [2] <span class="black">£61</span>
## [3] <span class="black">470m</span>
## [4] <span class="black">-30</span>
## [5] <span class="black">H2</span>
## [6] <span class="black">£105</span>
## [7] <span class="black">470m</span>
## [8] <span class="black">-30</span>
## [9] <span class="black">A7</span>
## [10] <span class="black">£61</span>
## [11] <span class="black">470m</span>
## [12] <span class="black">-30</span>
## [13] <span class="black">A5</span>
## [14] <span class="black">£66</span>
## [15] <span class="black">470m</span>
## [16] <span class="black">-30</span>
## [17] <span class="black">A8</span>
## [18] <span class="black">£61</span>
## [19] <span class="black">470m</span>
## [20] <span class="black">-20</span>
## ...

关于Rvest 无法识别 css 选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34473847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com