【发布时间】:2019-01-19 12:01:19
【问题描述】:
我想从以下网页提交表单:http://www.hzzo-net.hr/statos_OIB.htm
首先,我使用2captcha服务绕过recaptcha:
# parameters
api_key <- "c+++"
api_url <- "http://2captcha.com/in.php"
site_key <- "6Lc3SAgUAAAAALFnYxUbXlcJ8I9grvAPC6LFTKQs"
hzzo_url <- "http://www.hzzo-net.hr/statos_OIB.htm"
# GET method
req_url <- paste0("http://2captcha.com/in.php?key=", api_key,"&method=userrecaptcha&googlekey=",
site_key, "&pageurl=", hzzo_url)
get_response <- POST(req_url)
hzzo_content <- content(get_response)
hzzo_content <- xml_text(hzzo_content)
captcha_id <- stringr::str_extract_all(hzzo_content[[1]], "\\d+")[[1]]
# solve captcha
Sys.sleep(16L)
captcha2_solve <- function(apiKey, capstchaID){
req_url <- paste0("http://2captcha.com/res.php?key=", api_key,"&action=get&id=", capstchaID)
result <- GET(req_url)
captcha_content <- content(result)
hzzo_response <- xml_text(captcha_content)
hzzo_response <- strsplit(hzzo_response, "\\|")
return(hzzo_response)
# hzzo_response <- hzzo_response[[1]][[2]]
# return(hzzo_response)
}
hzzo_response <- captcha2_solve(api_key, captcha_id)
while(hzzo_response[[1]] == "CAPCHA_NOT_READY"){
Sys.sleep(16L)
hzzo_response <- captcha2_solve(api_key, captcha_id)
return(hzzo_response)
}
hzzo_response <- hzzo_response[[1]][[2]]
执行此代码后,我得到了输入到 recaptcha 的 textarea 的响应。正如我所料,这部分工作正常。响应如下所示:
"03AHqfIOmo9BlCsCKyg-lDes4oW-U3PWgCtATRUqXFcEV032acDgGoOzrV8GiZNDzCF4TbCVLcY8HZ8hR1JqO11YdRExvgPDL0EUsjCZdI0rUm_LnBRRifyb66X7V6r4n8CIm1si3EKmw36XIcZK7MGrHSNWRrj2aGzWAYO8ceobViOICOhkYe9Bsfv64tUHWvHSqNIoesD_FHplbWG3B0eMag5341NyycjpNLxgNCwVzA8mhCU3oQUcloze-mIclFMZ7J_nbVhXdy8-qipF5ZFH4xIhSQXHH-TqxyaGQFjKdgLch7MuDEQVRcQGo1o4QuSEoeCTjlPn3Mah5vC8zKrnqfbMgiOVOIDJFGvFY4KOivbBzYTz5nW9g"
之后,我应该提交表单。这是我做错的部分。
我尝试将所有参数添加到 POST:
parameters <- list(
'upoib' = "93335620125", # example of number to enter
'g-recaptcha-response' = hzzo_response
)
test <- POST(
"http://www.hzzo-net.hr/statos_OIB.htm",
body = toJSON(parameters),
encode = "json",
verbose()
)
但这只是给我初始页面。
如果我有 recaptcha 响应变量,如何提交表单?是否可以使用 httr 包提交,或者我必须使用 Selenium。代码可以是 R 或 Python(只需要最后一部分,POST 函数)。
【问题讨论】:
-
我建议你看看 Python 中的 requests (docs.python-requests.org/en/master) 包。
-
我熟悉 R 中的 httr 包。我想它类似于 python 中的请求包。我已经在上面的代码中使用了它,并得到了 200 返回码。但是html源不对。所以,我不确定阅读文档是否会有所帮助(我需要大约 3 天的时间来从头到尾学习它)。
-
我已经进行了快速手动测试,似乎发布请求还期望
x和y作为参数(我不知道它们的意思)超出了g-recaptcha-response和 @987654329 @。不会是问题吧? -
当我在 r 中使用 rvest pacjage 中的 html_form 时,它显示了 2 个输入,但没有我们“”的名称。 Onecis 是图像。选择可以从 1 到 4
标签: python r recaptcha httr 2captcha