python爬取百度贴吧图片下载
import requests
from lxml import etree
index_url = "https://tieba.baidu.com/p/7209614779"
response = requests.get(index_url).text
selector = etree.HTML(response)
image_urls = selector.xpath('//img[@class="BDE_Image"]/@src')
offset = 0
for image_url in image_urls:
image_content = requests.get(image_url).content
with open('{}.jpg'.format(offset),'wb') as f:
f.write(image_content)
offset = offset + 1
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
因特吧!
喜欢就支持一下吧