Answer the question
In order to leave comments, you need to log in
How to get a png file from a website using lxml?
The site has such a block with such a png file, how can I get it (download)?
<div class="reader-view" data-p="2">
<img src="https://img4.example.me//example1/example2/examples/8-37/02.png">
</div>
Answer the question
In order to leave comments, you need to log in
from lxml import html
lxml_string = '''<div class="reader-view" data-p="2">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/274px-PNG_transparency_demonstration_1.png">
</div>'''
tree = html.document_fromstring(lxml_string)
pic_path = tree.xpath('//img/@src')[0]
import requests
r = requests.get(pic_path, allow_redirects=True)
open('d:\\02.png', 'wb').write(r.content)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question