import requests,os,re
from lxml import etree
from urllib import request
def parse_page(url):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36'
}
response = requests.get(url,headers=headers)
text = response.text
html = etree.HTML(text)
imgs = html.xpath("//div[@class='page-content text-center']//img")
for img in imgs:
img_url = img.get('data-original')
alt = img.get('alt')
alt = re.sub(r'[\/ :* ??“ < > ”|]','',alt)
suffix = os.path.splitext(img_url)[1]
filename = alt+suffix
request.urlretrieve(img_url,'images/'+filename)
def main():
for x in range(1,401):
url = 'https://www.doutula.com/photo/list/?page={}'.format(x)
parse_page(url)
if __name__ == '__main__':
main()
【爬虫练手】表情包爬虫
最新推荐文章于 2024-05-02 01:59:55 发布