如何使用mechanize生成验证码图像

min*_*ter 9 python captcha mechanize

我正在尝试使用python和mechanize从我的移动提供商网站发送短信.
问题是表单有一个验证码图像.使用mechanize我可以获得图像的链接,但是在我访问该链接时它会有所不同.
有没有办法从机械化中获取精确的图片?

cer*_*ros 11

这是如何获取图像的一个粗略示例,请注意,机械化使用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()
Run Code Online (Sandbox Code Playgroud)

id='id_of_image'是一个示例,BeautifulSoup提供了许多方法来查找您正在寻找的标记(请参阅BeautifulSoup文档).image_response是一个类似文件的对象.