【发布时间】:2021-07-02 13:59:50
【问题描述】:
我很确定.. 在社区的某个地方,这个问题已经得到解答。但由于某些原因,我找不到我想要的答案。 我最近才开始在 R 中进行文本挖掘和网页抓取。 而且我很难理解 html 代码(之前也没有使用过 html),我可以从一个网站/页面上抓取我想要的所有信息。 但我希望我能为这个网站的所有“下一页”做到这一点。 我编写了一个替代方案,但使用起来不太方便。
# I know the website has 9902 items and 50 items per page:
i <- 1
info <- c()
while (i < 9902) {
print(i)
i = i+50
info <- c(info,i)
}
URL_OG <- "https://www.imdb.com/search/title/?title_type=feature&year=2020-01-01,2020-12-31&start="
URL_OG_end <- "&ref_=adv_nxt"
create_URL <- function(x) {
paste0(URL_OG,x,URL_OG_end)
}
URLS <- unlist(lapply(info,create_URL))
# Now I have a list of URLS. But this is a stupid solution...
我可以使用 html_nodes(text,css='.next-page') 什么的吗? 非常感谢
【问题讨论】:
标签: r url web-scraping