【问题标题】:How to get generated captcha image using mechanize如何使用 mechanize 获取生成的验证码图像
【发布时间】:2011-08-03 10:20:15
【问题描述】:

我正在尝试使用 python 和 mechanize 从我的移动提供商网站发送短信。
问题是表单有一个验证码图像。使用 mechanize 我可以获得图像的链接,但每次访问该链接时它都不同。
有什么方法可以从 mechanize 获得准确的图片?

【问题讨论】:

  • 尝试获取图片内容而不是src
  • 据我所知 mechanize 只提供页面的源代码(

标签: python captcha mechanize


【解决方案1】:

这是一个如何获取图像的粗略示例,请注意 mechanize 使用 cookie,因此接收到的任何 cookie 都将与图像请求一起发送到服务器(这可能是您想要的 )。

br = mechanize.Browser()
response = br.open('http://example.com')
soup = BeautifulSoup(response.get_data())
img = soup.find('img', id='id_of_image')
image_response = br.open_novisit(img['src'])
image = image_response.read()

id='id_of_image' 是一个示例,BeautifulSoup 提供了多种方法来查找您要查找的标签(请参阅BeautifulSoup docs)。 image_response 是一个类似文件的对象。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多