I'm trying to use python and mechanize to send sms from my mobile provider website.
The problem is that form has a captcha image. Using mechanize I can get the link to the image, but it's different all the time I access that link.
Is there any way to get exact picture from mechanize?
我正在尝试使用python和机械化从我的手机供应商的网站发送短信。问题是表单有一个验证码映像。使用mechanize我可以获得到图像的链接,但是每次访问该链接时,它都是不同的。有没有办法从机械化中得到确切的图像?
1 个解决方案
#1
11
This is a rough example of how to get the image, note that mechanize uses cookies so any cookies received will be sent to the server with the request for the image (this is probably what you want).
这是如何获取图像的一个粗略示例,请注意,机械化使用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'
is an example, BeautifulSoup
provides many ways to find the tag you're looking for (see the BeautifulSoup docs). image_response
is a file-like object.
id='id_of_image'就是一个例子,BeautifulSoup提供了许多找到您要查找的标记的方法(请参阅BeautifulSoup文档)。image_response是一个类文件的对象。
#1
11
This is a rough example of how to get the image, note that mechanize uses cookies so any cookies received will be sent to the server with the request for the image (this is probably what you want).
这是如何获取图像的一个粗略示例,请注意,机械化使用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'
is an example, BeautifulSoup
provides many ways to find the tag you're looking for (see the BeautifulSoup docs). image_response
is a file-like object.
id='id_of_image'就是一个例子,BeautifulSoup提供了许多找到您要查找的标记的方法(请参阅BeautifulSoup文档)。image_response是一个类文件的对象。