我正在使用RCurl来抓取情绪数据,但我需要让它先等待几秒钟,然后才能抓取,这是我的初始代码:
library(stringr)
library(curl)
links <- "https://www.dailyfx.com/sentiment"
con <- curl(links)
open(con)
html_string <- readLines(con, n = 3000)
html_string[1580:1700] #The data value property is "--" in this case
如何正确添加等待秒数?
1条答案
按热度按时间pgx2nnw81#
特别感谢@MrFlick为您安排了
curl只提取该网页的源代码,页面上显示的数据在页面加载后通过javascript加载;它不包含在页面源代码中。如果您希望与使用javascript的页面交互,则需要使用类似RSelenium的代码。或者,您需要对javascript进行反向工程以查看数据来自何处,然后可能直接向数据端点而不是HTML页面发出curl请求
话虽如此,我还是使用RSelenium来实现这一点: