【问题标题】:Sumit captcha and other values using Urllib or Urllib2 python使用 Urllib 或 Urllib2 python 提交验证码和其他值
【发布时间】:2013-09-05 12:39:25
【问题描述】:

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

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() 它再次打开具有不同验证码图像的新页面。 我希望任何人都可以帮助我解决这个问题。 提前致谢。

【问题讨论】:

    标签: python urllib2 urllib


    【解决方案1】:

    这可能是因为您没有保存 cookie。 urllib2 可以帮助你解决这个问题;如果你像这样设置你的开瓶器:

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

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

    【讨论】:

      猜你喜欢
      • 2016-03-11
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2019-06-26
      • 2011-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多