【发布时间】:2018-01-09 02:20:11
【问题描述】:
我是 rvest 新手。如何提取标签中有 2 个类名或只有 1 个类名的元素?
这是我的代码和问题:
doc <- paste("<html>",
"<body>",
"<span class='a1 b1'> text1 </span>",
"<span class='b1'> text2 </span>",
"</body>",
"</html>"
)
library(rvest)
read_html(doc) %>% html_nodes(".b1") %>% html_text()
#output: text1, text2
#what i want: text2
#I also want to extract only elements with 2 class names
read_html(doc) %>% html_nodes(".a1 .b1") %>% html_text()
# Output that i want: text1
这是我的机器规格:
操作系统:Windows 10。
rvest 版本:0.3.2
R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
有人可以帮忙吗?
【问题讨论】:
标签: html r web-scraping scrape rvest