使用RVEST对<dl> <dt> <dd> html标签进行网络抓取

时间:2020-05-06 19:23:10

标签: html r web-scraping rvest

我试图使用rvest从二手车广告中抓取一些数据。但是,我无法使用html_nodes()函数抓取构成

html标签的一部分的数据。

更具体地说,我想在数据框中将以下汽车广告下图中的功能抓取到。 https://www.autoscout24.be/nl/aanbod/mercedes-benz-slk-200-benzine-grijs-e77f7a3e-76b1-4676-88a0-b52c9574068a?cldtidx=3&cldtsrc=listPage

enter image description here

有人可以帮我吗?

谢谢! Arne

2 个答案:

答案 0 :(得分:0)

我已经尝试过了(以及其他几种组合-反复试验)。我想有一个数据框,其中

标签是键,而
标签是值

install.packages("rvest")    
library(rvest)

autoscout_mercedes <- read_html("https://www.autoscout24.be/nl/lst/mercedes-benz?sort=standard&desc=0&ustate=N%2CU&cy=B&atype=C")

features <- autoscout_mercedes %>%    
      html_nodes("div.sc-ellipsis") %>%    
      html_nodes("a") %>%    
      html_attr("href")    

features

我还提供了html脚本的打印屏幕。enter image description here

答案 1 :(得分:0)

这将是我的方法,使用此示例链接:

link <- read_html("https://www.autoscout24.de/angebote/opel-corsa-1-2-16v-klima- 
                   nsw-zv-benzin-blau-f189ee9d-b634-4bb7-8051-0e4a1f62846f? 
                   &cldtidx=1&cldtsrc=listPage&searchId=1225151069")
name <- html_text(html_nodes(link, "dl > dt"))
name
value <- html_text(html_nodes(link, "dd"))
value
test <- data.frame(name,value)

head(test)
         h2            dd
1        Zustand \nGebraucht\n
2 Fahrzeughalter         \n3\n
3          Marke      \nOpel\n
4         Modell     \nCorsa\n
5  Erstzulassung      \n2000\n
6     Außenfarbe      \nBlau\n