9

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?

2
  • Try to get image content instead of src Commented Apr 11, 2011 at 21:45
  • As I know mechanize provides only source code of the page( Commented Apr 11, 2011 at 21:50

1 Answer 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).

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.