Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/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
使用rvest忽略div类_R_Xpath_Web Scraping_Rvest - Fatal编程技术网

使用rvest忽略div类

使用rvest忽略div类,r,xpath,web-scraping,rvest,R,Xpath,Web Scraping,Rvest,我正在尝试提取页面的一部分,同时忽略其中一个嵌套字段“ratings”。以下语法都无法成功提取我需要的内容。有什么建议吗 raw <- read_html(res[[1]]) %>% html_nodes(xpath = '(//div[@class="results" and not(div[contains(@class, "span4 mobile-span1 ratings")])]') raw <- read_html(res[[1]]) %>%

我正在尝试提取页面的一部分,同时忽略其中一个嵌套字段“ratings”。以下语法都无法成功提取我需要的内容。有什么建议吗

raw <- read_html(res[[1]])  %>%
  html_nodes(xpath = '(//div[@class="results" and not(div[contains(@class, "span4 mobile-span1 ratings")])]') 

raw <- read_html(res[[1]])  %>%
  html_nodes(xpath = '(//div[not(contains(@class, "span4 .mobile-span1 .ratings"))]//div[@class="results"])')
raw%
html_节点(xpath=”(//div[@class=“results”和not(div[contains(@class,“span4 mobile-span1 ratings”))]))
原始%
html_节点(xpath='(//div[not(contains(@class,“span4.mobile-span1.ratings”))]//div[@class=“results”]))

您是否尝试过vignette('selectorgadget',package='rvest')?是的,我尝试过。我之所以对排除特定嵌套div标记的方法感兴趣,是因为我可以通过循环提取多个页面。由于特定字段的长度不均匀(即,该字段没有任何内容),循环被抛出.I不能使用html_表()因为信息不在表中。如果您使用一些示例HTML进行编辑,并选择与之匹配或不匹配的内容,则更有可能得到有用的答案。不过,作为一般策略,有时使用
HTML\u节点
最容易获取比您需要的更多的内容,然后在事后将其切碎。如果网站(a)不是内部的,并且(b)没有限制性的ToS,或者(c)需要登录,请发布URL。如果是(b)请不要用它来破坏民法和违反ToS给R一个坏名声。如果是(a)或者(c)请提供一些HTML代码片段。