我可以添加什么样的代码,这样我就可以避免有时出现的captcha,或者填充特定的captcha



这是我的实际脚本,在captcha出现之前运行良好。

driver.get("https://www.tppcrpg.net/battle_trainer.php")
# identify Enter Trainer Name/Number
driver.find_element_by_name("Trainer").send_keys(Trainer_Battle_ID)
driver.find_element_by_class_name("submit").click()
for x in range(100):
driver.find_element_by_class_name("submit").click()
time.sleep(1.5)
driver.find_element_by_xpath("//input[@value='Continue >>']").click()

这种captcha有时会出现在这个网站

https://i.stack.imgur.com/MfLyF.jpg

我还设法获得了这个captcha 的源代码页

https://i.stack.imgur.com/EmS0u.jpg

我试着自己添加一些脚本,这样每当出现captcha时,它就会填写并继续工作,但失败了

我在下面发布了我试图创建的代码

driver.get("https://www.tppcrpg.net/battle_trainer.php")
# identify Enter Trainer Name/Number
driver.find_element_by_name("Trainer").send_keys(Trainer_Battle_ID)
driver.find_element_by_class_name("submit").click()
time.sleep(1.0)
if("CAPTCHA"):
# Execute a script in the browser
webbrowser.execute_script("""
// Set the value of the input to the value of the CAPTCHA text
document.querySelector("#txtInput").value = document.querySelector("#txtCaptcha").value
""")
time.sleep(1.5)
driver.find_element_by_class_name("submit").click()
else :
for x in range(100):
driver.find_element_by_class_name("submit").click()
time.sleep(1.5)
driver.find_element_by_xpath("//input[@value='Continue >>']").click()

但是第二个代码失败了。有没有办法避开captchas或填写它。我在上面发布了一个captcha的例子,通常这种captcha有时会出现在之后本阶段

driver.get("https://www.tppcrpg.net/battle_trainer.php")
# identify Enter Trainer Name/Number
driver.find_element_by_name("Trainer").send_keys(Trainer_Battle_ID)
driver.find_element_by_class_name("submit").click()
time.sleep(1.0)

非常小的世界。事实上,几年前我和你在同一个网站上做过同样的事情。我从来没有想出一个很好的方法来处理它,但我的一个想法是使用图像识别来提取字符,然后填充字段。我从来没有抽出时间,所以我不得不自己手动填写captcha。祝你好运,先生。

相关内容