我正在使用包 RCurl 从巴西的网站下载一些价格,但为了加载数据,我必须首先从表单中选择一个城市。
该网站是:“ http://www.muffatosupermercados.com.br/Home.aspx ”
我想要 CURITIBA 的价格,id=53。
我正在尝试使用这篇文章中提供的解决方案:“如何在 RCurl 中使用 cookie? ”
这是我的代码:
library("RCurl")
library("XML")
#Set your browsing links
loginurl = "http://www.muffatosupermercados.com.br"
dataurl = "http://www.muffatosupermercados.com.br/CategoriaProduto.aspx?Page=1&c=2"
#Set user account data and agent
pars=list(
id = "53"
)
agent="Mozilla/5.0" #or whatever
#Set RCurl pars
curl = getCurlHandle()
curlSetOpt(cookiejar="cookies.txt", useragent = agent, followlocation =TRUE, curl=curl)
#Also if you do not need to read the cookies.
#curlSetOpt( cookiejar="", useragent = agent, followlocation = TRUE, curl=curl)
#Post login form
html=postForm(loginurl, .params = pars, curl=curl)
#Go wherever you want
html=getURL(dataurl, curl=curl)
C1 <- htmlParse(html, asText=TRUE, encoding="UTF-8")
Preco <- C1 %>% html_nodes(xpath = "//li[@class='preco']") %>% html_text(xmlValue, trim = TRUE)
但是当我运行代码时,我只得到表单后面的页面,而不是预期的页面:
“ http://www.muffatosupermercados.com.br/CategoriaProduto.aspx?Page=1&c=2 ”
我也试过玩饼干,但没有运气。
有谁知道如何提交此表单并加载正确的页面?
tks提前...