r - Web 在 R 中抓取 HTML 表格需要大量时间
问题描述
伙计们,我正在尝试抓取一个只有大约 1000 多条记录的链接,但要花几个小时才能得到它们。想知道我是否做错了什么或将其加载到表中的方法。
urlString = "https://www.valueresearchonline.com/funds/selector-data/primary-category/1/equity/?tab=snapshot&output=html-data"
urlString <- URLencode(paste0(urlString,""))
#Reading the HTML code from the website and process the text
getHTML <- xml2::read_html(urlString, options = "HUGE")
#This one keeps running endlessly and doesn't load the table
mytable <- data.frame(getHTML %>% html_table(fill = T, trim = T))
任何帮助,将不胜感激。谢谢
解决方案
该链接是一个 JSON 文件。您需要先阅读它jsonlite
。HTML 数据位于html_data
节点上,您可以通过以下方式读取此节点read_html
:
json <- jsonlite::fromJSON("https://www.valueresearchonline.com/funds/selector-data/primary-category/1/equity/?tab=snapshot&output=html-data")
getHTML <- xml2::read_html(json$html_data)
mytable <- data.frame(getHTML %>% html_table(fill = T, trim = T))
推荐阅读
- symfony - Twig Symfony 5 中的复数
- javascript - 从一个集合中获取与另一个集合文档具有匹配数据的文档
- javascript - 如何在不同组件的vue js中实现平滑滚动?
- windows - 安排要执行的任务而无需用户登录
- javascript - TypeError:User.pre 不是函数
- javascript - 单击父子组件之外的按钮时,如何将数据父组件发送到子组件?
- javascript - 如何知道请求来自超级代理?
- c# - ServiceStack 未出现在 Visual Studio 中
- haskell - 如何在 Haskell 中获取上个月的开始时间?
- regex - 我如何匹配确切的单词边界,但不包括前后的特殊字符?