如何废弃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
1 回答
@ jso1226,我不确定你所引用的答案中发生了什么,所以我提供了一个与你想要做的非常相似的例子 .
其中:转到网页收集信息,添加数据框,然后转到下一页 .
我使用这个代码创建来跟踪我在这里发布到stackoverflow的答案:
在这种情况下,循环仅限于5页,这需要更改以适合您的应用程序 . 我用******替换了用户特定的值,希望这将为您提供一些指导 .