【发布时间】:2017-02-05 21:01:13
【问题描述】:
如何抓取 70 个页面的 html 数据?我在看这个question,但我被一般方法部分的功能卡住了。
#attempt
library(purrr)
url_base <-"https://secure.capitalbikeshare.com/profile/trips/QNURCMF2Q6"
map_df(1:70, function(i) {
cat(".")
pg <- read_html(sprintf(url_base, i))
data.frame( startd=html_text(html_nodes(pg, ".ed-table__col_trip-start-date")),
endd=html_text(html_nodes(pg,".ed-table__col_trip-end-date")),
duration=html_text(html_nodes(pg, ".ed-table__col_trip-duration"))
)
}) -> table
#attempt 2 (with just one data column)
url_base <-"https://secure.capitalbikeshare.com/profile/trips/QNURCMF2Q6"
map_df(1:70, function(i) {
page %>% html_nodes(".ed-table__item_odd") %>% html_text()
}) -> table
【问题讨论】:
-
您的网址应该在某处有一个参数,表示当前页码,然后您应该将其与
url_base一起粘贴以生成实际的网址。现在看来您正尝试访问同一个网址 70 次
标签: r web-scraping