一些图片的爬取python

具体图片 请看代码详情

下面展示一些 内联代码片

import requests
import os

if not os.path.exists('./huashitong'):
    os.makedirs('./huashitong')

def get_pic(response_data):
    for line in response_data['data']['datas']:
        if 'coverImage' in line['data']:
            url = 'https://img2.huashi6.com/'+line['data']['coverImage']['originalPath']
            filename = line['data']['title']
            sets = ['/', '\\', ':', '*', '?', '"', '<', '>', '|']
            for char in filename:
                if char in sets:
                    filename = filename.replace(char, '')
            filename.split()
            pic_data =requests.get(url = url ,headers = headers).content
            picPath = './huashitong/'+ filename+'.jpg'
            with open(picPath,'wb+') as f:
                f.write(pic_data)
                print(filename,'下载成功')
        elif 'worksList'in line['data']:
            for i in line['data']['worksList']:
                url = 'https://img2.huashi6.com/'+i['coverImage']['originalPath']
                filename = i['title']
                sets = ['/', '\\', ':', '*', '?', '"', '<', '>', '|']
                for char in filename:
                    if char in sets:
                        filename = filename.replace(char, '')
                filename.split()
                pic_data =requests.get(url = url ,headers = headers).content
                picPath = './huashitong/'+ filename+'.jpg'
                with open(picPath,'wb+') as f:
                    f.write(pic_data)
                    print(filename,'下载成功')
headers ={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36'
    }
page = int(input('enter a pages'))
for page in range(1,page):
    url = 'https://rt.huashi6.com/front/index/load_pc_data?_ts_=1636363387274&cursor={}-1636361232855'.format(page)
    response_data = requests.post(url = url,headers = headers).json()
    get_pic(response_data)
上一篇:Python爬虫从入门到精通:(45)JS逆向:空中网逆向分析:js混淆_Python涛哥


下一篇:使用爬虫IP代理的一些认知及误区