r - 需要登录的R中的网络抓取
问题描述
我想登录我的帐户并下载并继续在网站上继续,但我使用 rvest 包的 r 代码不起作用。
link_of_login <- "https://www.fio.cz/e-broker/e-broker.cgi"
pgsession <- html_session(link_of_login)
pgform <- html_form(pgsession)[[1]]
filled_form <- set_values(pgform, LOGIN_USERNAME="USERNAME", LOGIN_PASSWORD="PASSWORD")
submit_form(pgsession, filled_form)
但是 R 正在返回:错误:form
不包含action
属性。
之后我想 jump_to("https://www.fio.cz/e-broker/e-obchody.cgi")
我想提交登录信息的 GET 和 POST 方法可能有问题。那么有什么简单的解决方案吗?非常感谢。
解决方案
一种解决方案可能是RSelenium
下面是一个简单的例子
library(RSelenium)
#Selenium environment activation
rD <- RSelenium::rsDriver(browser = "firefox", check = FALSE)
remDr <- rD[["client"]]
remDr$navigate("https://www.fio.cz/e-broker/e-broker.cgi")
#Click to activate the field and send the username
remDr$findElement(using = 'xpath', value = '/html/body/div/form/div[1]/div[1]/div[5]/table/tbody/tr[1]/td[2]/input')$clickElement()
remDr$findElement(using = 'xpath', value = '/html/body/div/form/div[1]/div[1]/div[5]/table/tbody/tr[1]/td[2]/input')$sendKeysToElement(list('USERNAME'))
#Click to activate the field and send the password
remDr$findElement(using = 'xpath', value = '/html/body/div/form/div[1]/div[1]/div[5]/table/tbody/tr[1]/td[2]/input')$clickElement()
remDr$findElement(using = 'xpath', value = '/html/body/div/form/div[1]/div[1]/div[5]/table/tbody/tr[2]/td[2]/input')$sendKeysToElement(list('PASSWORD'))
#Click the bottom
remDr$findElement(using = 'xpath', value = '/html/body/div/form/div[1]/div[1]/div[5]/table/tbody/tr[3]/td[2]/input')$clickElement()
推荐阅读
- python-2.7 - Ruamel.yaml.jinja2: typ "jinja2" 在 CentOS 上无法识别
- c# - 运算符“==”不能应用于 C# 中“方法组”和“字符串”样式 ID 类型的操作数
- python - 为什么在 pytorch 中保存和加载模型权重后得到不同的结果?
- django - 无法在调试 = False(生产)中使用 Django 启动工作进程 Celery 任务
- python - 在 Python 中输出一个 sqlite 记录
- java - 为什么我们需要使用标记接口?
- google-maps - 开发目的即使在 https 请求中添加客户端 ID 和密钥后也只有水印
- python - Python连接多个unicode字符串和变量
- c - 为什么这个程序没有打印在我的文件上?
- vue.js - 迭代抛出的具有几乎相似名称的输入元素