提交JavaScript的请求以解决Python的Recaptcha
我目前正在尝试通过Selenium和2Captcha登录站点。
除了验证码外,一切现在都可以正常工作。 当我尝试提交请求时,我会出现错误。
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import requests, time
user_name = ""
password = ""
api_key = ''
site_key = '6LcZlE0UAAAAAFQKM6e6WA2XynMyr6WFd5z1l1Nr'
page_url = 'https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/'
def Solver():
chrome_options = Options()
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options,service=Service(ChromeDriverManager().install()))
driver.get(page_url)
element = driver.find_element_by_id("login-email")
element.send_keys(user_name)
element = driver.find_element_by_id("login-password")
element.send_keys(password)
driver.find_element_by_id("gdpr-banner-accept").click()
u1 = f"https://2captcha.com/in.php?key={api_key}&method=userrecaptcha&googlekey={site_key}&pageurl={page_url}&json=1&invisible=1"
r1 = requests.get(u1)
print(r1.json())
rid = r1.json().get("request")
u2 = f"https://2captcha.com/res.php?key={api_key}&action=get&id={int(rid)}&json=1"
time.sleep(5)
while True:
r2 = requests.get(u2)
print(r2.json())
if r2.json().get("status") == 1:
form_tokon = r2.json().get("request")
break
time.sleep(5)
wirte_tokon_js = f'document.getElementById("g-recaptcha-response").innerHTML="{form_tokon}";'
submit_js = 'document.getElementById("recaptcha-demo-form").submit();'
print(wirte_tokon_js)
print('')
print(submit_js)
driver.execute_script(wirte_tokon_js)
time.sleep(3)
driver.execute_script(submit_js)
time.sleep(10)
if __name__ == '__main__':
Solver()
这是我遇到的错误。
selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read properties of null (reading 'submit')
这将是我解决验证码的最后一个方法。我尝试单击它,即使使用验证码框架的确切位置单击框
I am Currently trying to log into a Site via Selenium and 2Captcha.
Everything work fine right now except the Captcha.
When I try to submit the request, I get an Error.
#!/usr/bin/python3
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import requests, time
user_name = ""
password = ""
api_key = ''
site_key = '6LcZlE0UAAAAAFQKM6e6WA2XynMyr6WFd5z1l1Nr'
page_url = 'https://www.ebay-kleinanzeigen.de/m-einloggen.html?targetUrl=/'
def Solver():
chrome_options = Options()
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_experimental_option("detach", True)
driver = webdriver.Chrome(options=chrome_options,service=Service(ChromeDriverManager().install()))
driver.get(page_url)
element = driver.find_element_by_id("login-email")
element.send_keys(user_name)
element = driver.find_element_by_id("login-password")
element.send_keys(password)
driver.find_element_by_id("gdpr-banner-accept").click()
u1 = f"https://2captcha.com/in.php?key={api_key}&method=userrecaptcha&googlekey={site_key}&pageurl={page_url}&json=1&invisible=1"
r1 = requests.get(u1)
print(r1.json())
rid = r1.json().get("request")
u2 = f"https://2captcha.com/res.php?key={api_key}&action=get&id={int(rid)}&json=1"
time.sleep(5)
while True:
r2 = requests.get(u2)
print(r2.json())
if r2.json().get("status") == 1:
form_tokon = r2.json().get("request")
break
time.sleep(5)
wirte_tokon_js = f'document.getElementById("g-recaptcha-response").innerHTML="{form_tokon}";'
submit_js = 'document.getElementById("recaptcha-demo-form").submit();'
print(wirte_tokon_js)
print('')
print(submit_js)
driver.execute_script(wirte_tokon_js)
time.sleep(3)
driver.execute_script(submit_js)
time.sleep(10)
if __name__ == '__main__':
Solver()
This is the Error I get.
selenium.common.exceptions.JavascriptException: Message: javascript error: Cannot read properties of null (reading 'submit')
this would be my last approach to solve the captcha.. I tried clicking it, even using the exact position to of the captcha frame to click the box
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是正确的方式。
在此代码中使用此方法,这是正确的方法。
this is not right way.
use this for this code, this is the right way.