【发布时间】:2022-01-28 01:49:03
【问题描述】:
我正在尝试使用 r 库 rvest 从博彩网站上抓取一些数据。
为了获取这些值,我需要单击表格中的一些超链接。
为此,我使用以下代码:
odds_link <- "https://www.oddsportal.com/soccer/germany/bundesliga/results/"
odds_page <- read_html(odds_link)
node_table <- html_node(xpath = '//*[@id="tournamentTable"]')
我使用了这个 xpath 并且 node_table 返回了这个
{xml_nodeset (1)}
[1] <div id="tournamentTable"></div>\n
返回的节点看起来是空的,因为 div 标签之间没有任何内容......它应该看起来像that。
在这一点上,我很失落。我尝试了几件事,但都没有成功。
node_table %>% html_node("table")
node_table %>% html_table()
node_table %>% html_structure()
这个被退回了:
> node_table %>% html_node("table")
{xml_missing}
<NA>
> node_table %>% html_table()
Fehler in html_table.xml_node(.) : html_name(x) == "table" is not TRUE
> node_table %>% html_structure()
<div#tournamentTable>
非常感谢您对此的帮助!
(下一步是访问表中的these 超链接。)
我什至无法访问超链接...
xpath_link = '//*[@id="tournamentTable"]/tbody/tr[4]/td[2]/a'
odds_page %>% html_node(xpath = xpath_link)
> odds_page %>% html_node(xpath = xpath_link)
{xml_missing}
<NA>
【问题讨论】:
-
该表由 Javascript 呈现。您可能需要
RSelenium来完成此任务。
标签: html r web-scraping rvest