【问题标题】:Webscraping of <dl> <dt> <dd> html tags using RVEST使用 RVEST 对 <dl> <dt> <dd> html 标签进行网页抓取
【发布时间】:2020-08-21 21:56:48
【问题描述】:

我正在尝试使用 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

谁能帮帮我?

谢谢! 阿恩

【问题讨论】:

  • 请添加您的代码
  • 嗨阿恩。欢迎来到 SO。请分享您的一些代码并向我们展示您迄今为止所做的尝试。
  • 请看下面的答案 :) 你介意看看吗?

标签: html r web-scraping rvest


【解决方案1】:

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

标签是键,
标签是值
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

【讨论】:

  • 嗨 Arne,您找到解决方案了吗? :) 我还想从 autoscout 中抓取数据
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 2018-11-26
    • 1970-01-01
    • 2019-10-11
    • 2018-12-03
    • 2011-11-27
    • 2018-02-15
    相关资源
    最近更新 更多