如何使用机械化获取验证码图像

问题描述 投票:9回答:2

我正在尝试使用python进行机械化,以从我的移动服务提供商网站发送短信。问题在于表单具有验证码图像。使用mechanize可以获取图像的链接,但是访问该链接的时间总是不同的。有什么办法可以从机械化中获得准确的照片吗?

python captcha mechanize
2个回答
11
投票

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

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是类似文件的对象。

0
投票
请帮助!

之后:

response = br.open(URL) soup = BeautifulSoup(response.get_data(),'lxml') img = soup.find('img', id='captcha_entry') image_response = br.open_novisit(img['src']) image = image_response.read()

错误:

'NoneType'对象不可下标
© www.soinside.com 2019 - 2024. All rights reserved.