使用 rvest 进行网络抓取:css 选择器以获取 "more text"

Web scraping using rvest: css selector to get "more text"

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

我尝试了不同的 css 选择器(使用 Selector Gadget 识别)但没有成功,并且捕获的文本并非所有可用的文本。

关于如何获得完整文本字段的任何想法?

谢谢!

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

该内容存储在元标记的内容属性中。您可以select如下:

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')