【发布时间】:2019-03-13 17:37:15
【问题描述】:
我在抓取 Transfermarket 时遇到问题。我想收集过去 20 个赛季欧洲前 5 名联赛(英超、西甲、意甲、法甲、德甲)的数据。在此我想收集一系列详细信息——球员姓名、年龄、球员位置、球员俱乐部、离开球员俱乐部、费用。但即使使用这个非常基本的代码,我只写了 18/19 英超联赛转会的一页,收集球队和名字(添加),我得到一个我不明白的错误。我也一直在使用选择器小工具。
我的代码:
require(rvest)
page = "https://www.transfermarkt.com/premier-league/transfers/wettbewerb/GB1/plus/?saison_id=2012&s_w=&leihe=0&leihe=1&intern=0"
scraped_page <- read_html(page)
Team_html = html_nodes(page, ".tooltipstered+ .tooltipstered")
Team = html_text(Team_html)
Addition_html = html_nodes(page, ".table-header+ .responsive-table .spielprofil_tooltip")
Addition = html_text(Addition_html)
df <- data.frame(Team, Addition)
head(df)
R 返回什么:
> page = "https://www.transfermarkt.com/premier-league/transfers/wettbewerb/GB1/plus/?saison_id=2012&s_w=&leihe=0&leihe=1&intern=0"
>
> scraped_page <- read_html(page)
>
> Team_html = html_nodes(page, ".tooltipstered+ .tooltipstered")
Error in UseMethod("xml_find_all") :
no applicable method for 'xml_find_all' applied to an object of class "character"
> Team = html_text(Team_html)
> Addition_html = html_nodes(page, ".table-header+ .responsive-table .spielprofil_tooltip")
Error in UseMethod("xml_find_all") :
no applicable method for 'xml_find_all' applied to an object of class "character"
> Addition = html_text(Addition_html)
>
>
> df <- data.frame(Team, Addition)
Error in data.frame(Team, Addition) :
arguments imply differing number of rows: 0, 922
>
> head(df)
1 function (x, df1, df2, ncp, log = FALSE)
2 {
3 if (missing(ncp))
4 .Call(C_df, x, df1, df2, log)
5 else .Call(C_dnf, x, df1, df2, ncp, log)
6 }
我正在考虑从这里开始,然后使用 gsub 和其他一些命令在几年和联赛中循环循环......
【问题讨论】:
标签: r web-scraping rvest