【问题标题】:Scraping Weblinks out of an Website using Rvest使用 Rvest 从网站中抓取 Web 链接
【发布时间】:2020-01-30 17:48:25
【问题描述】:

我是 r 和 Webscraping 的新手。我目前正在抓取一个房地产网站 (https://www.immobilienscout24.de/Suche/S-T/Wohnung-Miete/Rheinland-Pfalz/Koblenz?enteredFrom=one_step_search),但我无法抓取特定优惠的链接。

当使用下面的代码时,我获得了附加到网站的每个链接,我不太确定如何过滤它,使其只抓取 20 个房地产报价的链接。也许你能帮帮我。

到目前为止,查看源代码/检查元素对我没有帮助...

url <- immo_webp %>%

  html_nodes("a") %>%

  html_attr("href")

【问题讨论】:

标签: html r web-scraping rvest


【解决方案1】:

您可以定位 article 标签,然后通过连接基本字符串从 data-obid 属性构造 url

library(rvest)
library(magrittr)

base = 'https://www.immobilienscout24.de/expose/'

urls <- lapply(read_html("https://www.immobilienscout24.de/Suche/S-T/Wohnung-Miete/Rheinland-Pfalz/Koblenz?enteredFrom=one_step_search")%>%
       html_nodes('article')%>%
       html_attr('data-obid'), function (url){paste0(base, url)})
print(urls)

【讨论】:

    猜你喜欢
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-19
    • 1970-01-01
    • 2018-11-03
    相关资源
    最近更新 更多