【发布时间】:2018-01-02 15:42:23
【问题描述】:
我想用一些参数从this页面上抓取每个月的信息,下载所有返回的文章并查找一些信息。
抓取与 css 选择器配合得很好,例如获取文章名称:
library(rvest)
browseURL("http://www.sueddeutsche.de/news")
#headings Jan 2015
url_parsed1 <- read_html("http://www.sueddeutsche.de/news?search=Fl%C3%BCchtlinge&sort=date&dep%5B%5D=politik&typ%5B%5D=article&sys%5B%5D=sz&catsz%5B%5D=alles&time=2015-01-01T00%3A00%2F2015-12-31T23%3A59&startDate=01.01.2015&endDate=31.01.2015")
headings_nodes1 <- html_nodes(url_parsed1, css = ".entrylist__title")
headings1 <- html_text(headings_nodes1)
headings1 <- str_replace_all(headings1, "\\n|\\t|\\r", "") %>% str_trim()
head(headings1)
headings1
但现在我想下载搜索返回的每个 entrylist_link 的文章(例如 here)。
我该怎么做?我遵循了here 的建议,因为 URL 不规则,并且每篇文章最后都有不同的数字,但它不起作用。
不知何故,我无法通过 href 信息获取 entrylist_link 信息。
我认为将所有链接放在一个向量中是最大的问题
有人可以就如何让它发挥作用给我建议吗? 提前感谢您的帮助。
【问题讨论】:
标签: html css r web-scraping