我需要从使用 cookie 保护的网站下载信息。我手动传递此保护,然后将 cookie 插入到httr.
这是类似的主题,但它没有解决我的问题:(为 httr 复制 cookie)
library(httr)
url<-"http://smida.gov.ua/db/emitent/year/xml/showform/32153/125/templ"
cook<-"_SMIDA=9117a9eb136353bd6956651bd59acd37; __utmt=1; __utma=29983421.1729484844.1413489369.1413625619.1413627797.3; __utmb=29983421.7.10.1413627797; __utmc=29983421; __utmz=29983421.1413489369.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"
response <- GET(url, config(cookie= cook))
content(x = response,as = 'text', encoding = "UTF-8")
Run Code Online (Sandbox Code Playgroud)
因此,当我使用内容时,它会返回我未登录的信息(就像没有 cookie 时那样)
我怎么解决这个问题?
测试凭据是 login: mytest2, pass: qwerty12)
这将是set_cookies与GET&的方式httr:
GET("http://smida.gov.ua/db/emitent/year/xml/showform/32153/125/templ",
set_cookies(`_SMIDA` = "7cf9ea4bfadb60bbd0950e2f8f4c279d",
`__utma` = "29983421.138599299.1413649536.1413649536.1413649536.1",
`__utmb` = "29983421.5.10.1413649536",
`__utmc` = "29983421",
`__utmt` = "1",
`__utmz` = "29983421.1413649536.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)"))
Run Code Online (Sandbox Code Playgroud)
这对我有用,至少我认为它确实如此,因为我无法阅读该语言。返回的表具有相同的结构并且没有提示登录。
不幸的是,登录时的验证码会阻止使用 Rselenium(或其他类似的爬行包),因此您必须继续手动获取这些 cookie(或使用实用程序从会话中提取它们)。
最后,您现在可能要认真考虑更改这些凭据:-)
编辑: @VadymB和我都发现代码在我们重新启动 RStudio之前不起作用。你的旅费可能会改变。
| 归档时间: |
|
| 查看次数: |
5296 次 |
| 最近记录: |