gpt4 book ai didi

python - 使用 Urllib 或 Urllib2 python 提交验证码和其他值

转载 作者:太空宇宙 更新时间:2023-11-03 18:49:44 24 4
gpt4 key购买 nike

如何提交包含 Captch 图像的表单?尝试过这段代码

import urllib
import urllib2
from PIL import Image
import pytesser
#include the pytesser into the site pacakges
#and run sudo apt-get tesseract-ocr it is required by the
#pytesser to run the image converter

image = urllib.URLopener()
image.retrieve("http://www.stat.gov.pl/regon/Captcha.jpg","Captcha.jpg")
#The image get saved into current script directory
image = Image.open('Captcha.jpg')
print image_to_string(image) #I will get the text from the Captcha Image
text=image_to_string(image)

现在我想将此数据字典发送到帖子中打开的请求,以便获取包含详细信息的下一页

data={'criterion1TF':5213510101,'verifCodeTF':text}

但是当我使用urllib.URLopener()它再次打开具有不同验证码图像的新页面。我希望任何人都可以帮助我解决这个问题。提前致谢。

最佳答案

这可能是因为您没有保存 cookie。 urllib2 可以帮助你;如果你像这样设置你的开场白:

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

然后它将透明地保存并提交cookie。

关于python - 使用 Urllib 或 Urllib2 python 提交验证码和其他值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18636584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com