【发布时间】:2016-04-17 00:20:19
【问题描述】:
我有一个包含 URL 列表的文件
http://www.programmableweb.com/api-university
http://www.programmableweb.com/api-research
http://www.programmableweb.com/api/facebook
http://www.programmableweb.com/api/google-maps
我想使用 R,尤其是 rvest 用于网络抓取 https://blog.rstudio.org/2014/11/24/rvest-easy-web-scraping-with-r/。我基本上需要收集SPECS下的所有字段,比如
htmlpage <- read_html("http://www.programmableweb.com/api/swrve-events")
text1 <- html_nodes(htmlpage, ".field")
问题:
-
如何读取文件? 当我执行 read.csv(filename) 或 read.table(filename) 然后使用 read_html 时,它会说
no applicable method for 'read_xml' applied to an object of class "data.frame" 如何迭代文件?
【问题讨论】:
-
你可以 lapply(readLines(filepath), function(eachlink) ......
标签: r file url screen-scraping