Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.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:css选择器进行网页抓取以获取;“更多文本”;_R_Web Scraping_Css Selectors_Rvest - Fatal编程技术网

使用rvest:css选择器进行网页抓取以获取;“更多文本”;

使用rvest:css选择器进行网页抓取以获取;“更多文本”;,r,web-scraping,css-selectors,rvest,R,Web Scraping,Css Selectors,Rvest,我正在看一个从网站上抓取文本数据的例子,并努力从特定部分获取所有文本,特别是在该文本框有一个名为“阅读更多”的字段的部分 我尝试了不同的css选择器(使用选择器小工具识别),但没有成功,捕获的文本并不是所有可用的文本 关于如何获得完整的文本字段有什么想法吗 谢谢 library(rvest) link = "https://www.property24.com/for-sale/camps-bay/cape-town/western-cape/11014/109734849"

我正在看一个从网站上抓取文本数据的例子,并努力从特定部分获取所有文本,特别是在该文本框有一个名为“阅读更多”的字段的部分

我尝试了不同的css选择器(使用选择器小工具识别),但没有成功,捕获的文本并不是所有可用的文本

关于如何获得完整的文本字段有什么想法吗

谢谢

library(rvest)

link = "https://www.property24.com/for-sale/camps-bay/cape-town/western-cape/11014/109734849"

html_link = read_html(link)

# Method 1
text1 = html_link %>%
  html_nodes(css = ".js_readMoreText") %>%
  html_text()
text1

# Method 2
text2 = html_link %>%
  html_nodes(css = ".js_readMore") %>%
  html_text()
text2

# Method 3
text3 = html_link %>%
  html_nodes(css = ".expanded , .js_readMoreText") %>%
  html_text()
text3


该内容存储在元标记的内容属性中。您可以选择以下选项:

library(rvest)

link <- "https://www.property24.com/for-sale/camps-bay/cape-town/western-cape/11014/109734849"
html_link <- read_html(link)

description <- html_link %>%
  html_node('[property="og:description"]') %>%
  html_attr('content')
库(rvest)

链接是否可以分享您是如何识别元标记中的内容的?我在网页上使用了选择器小工具,这将有助于理解您是如何使用它的。非常感谢。