【发布时间】:2021-12-31 03:52:49
【问题描述】:
我想抓取 https://www.deutsche-biographie.de/ 。具体来说,我有兴趣抓取有关每个人的以下信息
- 姓名
- 出生年份
- 死亡年份
- 职业
- 出生地(源代码中的“geburt”)和坐标
- 死亡地点(源代码中的“tod”)和坐标
- 活动地点(源代码中的“wirk”)和坐标
使用下面的代码,我抓取了姓名、出生年份、死亡年份和职业。
library(rvest)
library(dplyr)
page = read_html(x = "https://www.deutsche-biographie.de/search?_csrf=45b6ee54-385e-4777-90bf-9067923e6a00&name=meier")
name = page %>% html_nodes(".media-heading a") %>% html_text()
information = page %>% html_nodes("#secondColumn p") %>% html_text()
result = data.frame(name, information, stringsAsFactors = FALSE)
#manipulate data in columns
result$yearofbirth = sub("(^[^-]+)-.*", "\\1", result$information) #extract characters before dash
result$yearofdeath = sub(',.*$','', result$information)
result$yearofdeath = sub('.*-','', result$yearofdeath) #extract characters after dash
result$profession = sub("^.*?,", "", result$information) #extract characters after comma
result$profession = trimws(result$profession, whitespace = "[ \t\r\n]") #trim leading and trailing white space
result$information = NULL
但是,我正在努力从
<li class="media treffer-liste-elem" id="treffer-sfz55763" data-orte="Rendsburg@54.3012661,9.6596678@geburt;Rendsburg@54.3012661,9.6596678@wirk;Kiel@54.3216753,10.1371858@wirk;Magdeburg@52.1315889,11.6399609@wirk;Rostock@54.14736345,12.109015599915@wirk;Frankfurt/Oder@52.3438922,14.5544166@wirk;Gottorf@54.5117924,9.54054973309832@wirk;Padua@45.407059,11.8767269@wirk;Bologna@44.4936714,11.3430347@wirk;Basel@47.5429886,7.5969912@wirk;Königsberg@54.7066424,20.5105165@wirk;Danzig@54.3482114,18.6542829@wirk;Prag@50.087656,14.4212126@wirk;Amsterdam@52.3710089,4.9001115@wirk;Frankfurt@50.1432793,8.6805975@wirk;Rostock@54.14736345,12.109015599915@wirk;Magdeburg@52.1315889,11.6399609@tod" data-name="Maier, Michael">
如果有任何关于如何刮擦这些地方的提示,我将不胜感激! 最好的,娜塔莉
【问题讨论】:
标签: r web-scraping rvest