【问题标题】:Scrape name of HTML attribute rvest抓取 HTML 属性 rvest 的名称
【发布时间】:2020-12-18 06:47:43
【问题描述】:

我正在尝试使用 rvest (https://www.stepstone.de/5/ergebnisliste.html?stf=freeText&ns=1&qs=%5B%5D&companyID=0&cityID=0&sourceOfTheSearchField=homepagemex%3Ageneral&searchOrigin=Homepage_top-search&ke=building+information+modeliing&ws=&ra=30) 抓取招聘信息网站。

我想提取职位发布的创建日期 (2020-12-07T02:13:28+01:00),可在此处找到:

<time class="" datetime="2020-12-07T02:13:28+01:00" timeago-id="17">vor 1 Woche</time>

但是,我只能设法获得职位发布是在多少天前创建的,例如vor 1 Woche(1 周前)。我的代码如下所示:

url = "https://www.stepstone.de/5/ergebnisliste.html?stf=freeText&ns=1&qs=%5B%5D&companyID=0&cityID=0&sourceOfTheSearchField=homepagemex%3Ageneral&searchOrigin=Homepage_top-search&ke=building+information+modeliing&ws=&ra=30"
read_html(url) %>%
  html_nodes('time') %>% 
  html_text()

很高兴有任何帮助!谢谢!

【问题讨论】:

  • 这些属性在原始 html 中不存在。它们是使用 javascript 从同一页面上深度嵌套的 json 字符串动态添加到您的浏览器中的。检索时间戳并非不可能,但提取它们需要大量解析。你最好在这里选择 RSelenium 路线

标签: r web-scraping rvest


【解决方案1】:

首先,“日期时间”是一个属性,因此您需要尝试利用 html_attr 或 html_attrs。

其次,更重要的是,我在您的任何节点(仅类)中都没有看到日期时间。您确定这是该网站上所有时间节点的属性吗?

> library(rvest)
> 
> url = "https://www.stepstone.de/5/ergebnisliste.html?stf=freeText&ns=1&qs=%5B%5D&companyID=0&cityID=0&sourceOfTheSearchField=homepagemex%3Ageneral&searchOrigin=Homepage_top-search&ke=building+information+modeliing&ws=&ra=30"
> test = read_html(url) %>%
+   html_nodes('time')
> 
> test
{xml_nodeset (25)}
 [1] <time class="">vor 1 Woche</time>
 [2] <time class="">vor 1 Woche</time>
 [3] <time class="">vor 2 Tagen</time>
 [4] <time class="">vor 1 Woche</time>
 [5] <time class="">vor 6 Tagen</time>
 [6] <time class="">vor 12 Stunden</time>
 [7] <time class="">vor 18 Stunden</time>
 [8] <time class="">vor 23 Stunden</time>
 [9] <time class="">vor 1 Woche</time>
[10] <time class="">vor 1 Tag</time>
[11] <time class="">vor 2 Tagen</time>
[12] <time class="">vor 1 Tag</time>
[13] <time class="">vor 6 Tagen</time>
[14] <time class="">vor 2 Tagen</time>
[15] <time class="">vor 2 Tagen</time>
[16] <time class="">vor 2 Tagen</time>
[17] <time class="">vor 2 Tagen</time>
[18] <time class="">vor 6 Tagen</time>
[19] <time class="">vor 1 Woche</time>
[20] <time class="">vor 1 Woche</time>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    • 2020-09-13
    • 2018-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    相关资源
    最近更新 更多