Save dynamic captcha image in page with requests/bs4

melonfacedoom Source

the image I would like to save is in stored in the HTML as follows:

<img class="captcha3" src="img/captcha3" alt="Captcha">

I can find the url and save the image with the following:

soup = BeautifulSoup(url, "lxml")
img = soup.find('img',{'class':'captcha3'})['src']

response = session.get(url+img, stream=True)
with open('img.png', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)

However, this loads a new captcha. I would like to save the one that has already loaded, but I can't quite figure it out. Any help would be appreciated. Thanks.

python-3.xbeautifulsouppython-requests

Answers

comments powered by Disqus