R-如何修复:将XPath复制到脚本中后出乎意料的令牌



我正在尝试从网站刮擦公司的描述。要访问公司说明,您必须单击公司名称,该网站将您引导到特定公司的另一页。为了设置此循环,我需要在X路径上复制,但是我在语法上遇到了麻烦,因为我遇到了意外的令牌错误。我是新手编码的,所以请尽可能简单地回答。

number <- c(156000:165000)
description <- NULL
for(i in 1:949){
  url <- paste0("https://congress.nsc.org/nsc2019/public/eBooth.aspx?IndexInList=0&FromPage=Exhibitors.aspx&ParentBoothID=&ListByBooth=true&BoothID=", 
                number[i])
description[i] <- url %>%
  read_html() %>% 
  html_nodes(xpath = paste(//*[@id="eboothContainer"]/p)) %>% 
  html_text()
}

更改以下行

html_nodes(xpath = paste(//*[@id="eboothContainer"]/p)) %>%  # <== incorrect

如下

html_nodes(xpath = "//*[@id='eboothContainer']/p") %>% # <== correct

刚刚调整了XPATH和代码线。

最新更新