最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

【Python超強(qiáng)爬蟲5天速成】學(xué)完可以接任何爬蟲副業(yè)!來者不拒!目前B站最完整

2023-02-22 23:27 作者:春雨如蘇  | 我要投稿
啦啦啦啦 我來交作業(yè)了


from lxml import etree
import requests
import re
import json

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50',
    'cookie': 'lv=1676985897; vn=1; ip_ck=4MCF4f//j7QuNzc0NjU4LjE2NzY5ODU4OTc=; Hm_lvt_ae5edc2bc4fc71370807f6187f0a2dd0=1676985897; Adshow=0; Hm_lpvt_ae5edc2bc4fc71370807f6187f0a2dd0=1676987325; questionnaire_pv=1676937645'
}

url = 'https://desk.zol.com.cn/meinv/'



def get_home_page(url):
    res = requests.get(url, headers=headers)
    res.encoding = 'GB2312'
    return res.text


def get_urls(html):
    et = etree.HTML(html)
    urls = et.xpath('/html/body/div/div/ul[@class="pic-list2  clearfix"]/li/a/@href')
    return urls


def get_imgs(urls):
    imgsrcs = []
    html = get_home_page(urls)
    obj = re.compile(r'var deskPicArr.*?=(?P<deskPicArr>.*?);', re.S)
    result = obj.search(html)
    deskPicArr = result.group('deskPicArr').strip()
    deskPic = json.loads(deskPicArr)
    msg = deskPic.get('list')
    for item in msg:
        oriSize = item.get('oriSize')
        imgsrc = item.get('imgsrc')
        imgsrc = imgsrc.replace('##SIZE##', oriSize)
        imgsrcs.append(imgsrc)
    return imgsrcs


def download(imgsrc):
    res = requests.get(url=imgsrc, headers=headers)
    name = imgsrc.split('/')[-1]
    with open(f'wallpaper/{name}', 'wb') as f:
        f.write(res.content)


def run():
    html = get_home_page(url)
    urls = get_urls(html)
    for u in urls[2:]:
        urls = 'https://desk.zol.com.cn/' + u[1:]
        imgsrcs = get_imgs(urls)
        for imgsrc in imgsrcs:
            download(imgsrc)


run()


【Python超強(qiáng)爬蟲5天速成】學(xué)完可以接任何爬蟲副業(yè)!來者不拒!目前B站最完整的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
湾仔区| 团风县| 滦南县| 淅川县| 甘孜| 商都县| 吉木乃县| 科技| 青神县| 刚察县| 钦州市| 湘乡市| 岗巴县| 莎车县| 肇庆市| 阳高县| 长寿区| 荥经县| 红安县| 娄烦县| 靖宇县| 宜君县| 兴义市| 白玉县| 开远市| 屏边| 道真| 大渡口区| 郴州市| 阜城县| 东兰县| 伊金霍洛旗| 株洲市| 胶南市| 贵德县| 南阳市| 阿鲁科尔沁旗| 德令哈市| 鄂托克旗| 保德县| 拉萨市|