Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的网页抓取_R - Fatal编程技术网

R中的网页抓取

R中的网页抓取,r,R,我正在用R练习我的网页抓取编码,无论我尝试什么网站,我都无法通过一个阶段 比如说, 我的目标是提取所有77所学校的名称(牛津到伦敦大都会) 所以我试着 library(rvest) url_college <- "https://www.thecompleteuniversityguide.co.uk/league-tables/rankings?s=Music" college <- read_html(url_college) info <- html_nodes(col

我正在用R练习我的网页抓取编码,无论我尝试什么网站,我都无法通过一个阶段

比如说,

我的目标是提取所有77所学校的名称(牛津到伦敦大都会)

所以我试着

library(rvest)
url_college <- "https://www.thecompleteuniversityguide.co.uk/league-tables/rankings?s=Music"
college <- read_html(url_college)
info <- html_nodes(college, css = '.league-table-institution-name')
info %>% html_nodes('.league-table-institution-name') %>% html_text()
库(rvest)

url\u college您似乎运行了两次
html\u nodes()
:首先在
college
上运行一个
xml\u文档(正确),然后在
info
上运行一个不正确的字符向量

请尝试以下方法:

url_college %>%
  read_html() %>%
  html_nodes('.league-table-institution-name') %>%
  html_text()
然后你还需要一个额外的步骤来清理学校名称;有人建议:

%>%
  str_replace_all("(^[^a-zA-Z]+)|([^a-zA-Z]+$)", "")

您似乎运行了两次
html\u nodes()
:首先在
college
上运行一个
xml\u文档(正确),然后在
info
上运行一个字符向量(不正确)

请尝试以下方法:

url_college %>%
  read_html() %>%
  html_nodes('.league-table-institution-name') %>%
  html_text()
然后你还需要一个额外的步骤来清理学校名称;有人建议:

%>%
  str_replace_all("(^[^a-zA-Z]+)|([^a-zA-Z]+$)", "")

当你在等待答案的时候,你应该在等待答案的时候阅读,你应该在等待答案的时候阅读,我知道了。。。但是您能解释一下为什么我们需要在str|u replace|all((^[^a-zA-Z]+)|([^a-zA-Z]+$),“)中使用OR运算符吗?它不是必须是AND运算符,因为我们正在用“”替换这两种模式吗?也许建议编辑的人可以解释:)我知道了。。。但是您能解释一下为什么我们需要在str|u replace|all((^[^a-zA-Z]+)|([^a-zA-Z]+$),“)中使用OR运算符吗?因为我们将两种模式都替换为“”,所以它不必是AND运算符吗?也许建议编辑的人可以解释:)