表情党抓取(单页) (网站已转移)

表情党抓取(单页) (网站已转移)

创建时间:2024-08-06

一、完整代码

import requests
from lxml import etree
url = 'https://qq.yh31.com/xq/wq/'
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0'
}
res = requests.get(url=url,headers=header)
res.encoding = res.apparent_encoding
data = res.text
tree = etree.HTML(data)
src_list = tree.xpath('//div[@class="sr"]//@data-src')
alt_list = tree.xpath('//div[@class="sr"]//@alt')
for src,alt in zip(src_list,alt_list):
    res = requests.get(url=src,headers=header)
    print(f'下载---{alt.strip()}---中')
    with open(f'./bqd/{alt}.png','wb') as f:
        f.write(res.content)

1.1 效果

posted @ 2024-08-07 00:06  随风小屋  阅读(11)  评论(0编辑  收藏  举报