我试图使解决旁路验证码,但没有工作。
import requests
import bs4
from twocaptcha import TwoCaptcha
import os
TwoCaptcha_api_key = ""
renew_url = ""
renew_session = requests.session()
renew_request = renew_session.get(renew_url)
renew_content = renew_request._content
renew_soup = bs4.BeautifulSoup(renew_content, 'lxml')
renew_sitekey = renew_soup.find('div', {"class":"g-recaptcha"})['data-sitekey']
renew_token = renew_soup.find('input', {"name":"_token"})['value']
solve = TwoCaptcha(TwoCaptcha_api_key)
result = solve.recaptcha(
sitekey=renew_sitekey,
url=renew_url)
recaptcha_response = result['code']
postdata = {"username": "AAAAAAA", "g-recaptcha-response": f"{recaptcha_response}", "_token": f"{renew_token}" }
renew_post = renew_session.post(renew_url, data=postdata)
print(renew_post)我得到了这个错误
Traceback (most recent call last):<br>
File "", line 18, in <module><br>
result = solve.recaptcha(<br>
AttributeError: 'TwoCaptcha' object has no attribute 'recaptcha'发布于 2021-03-14 15:50:55
我猜你说的是这个用来解决验证码的https://pypi.org/project/2captcha-python/#solve-captcha包。
我还猜测,您一定是使用了某个IDE来安装这个包,但它安装了一个错误的包。(https://pypi.org/project/TwoCaptcha/),它是原始包装器的包装器。
删除当前不正确的软件包pip uninstall TwoCaptcha并安装正确的pip install 2captcha-python
发布于 2021-03-14 15:43:01
该函数名为solve_recaptcha(),而不是recaptcha。(请参阅自述文件)1
下次遇到此错误时,您可以查找原始代码和文档,也可以添加对dir()的调用以查看可用的成员/方法:
solve = ...
print dir(solve)发布于 2021-10-28 20:33:43
在Ide中的pycharm或VS转到终端并通过此代码"pip3 install 2captcha-python“它将看起来像这个PS C:\Users\PycharmProjects\test> pip3 install 2captcha-python它将解决您的问题
https://stackoverflow.com/questions/66622115
复制相似问题