栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python爬虫模板

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python爬虫模板

import re,requests
from lxml import etree
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
def urls(url):
    res=requests.get(url)
    # html=etree.HTML(res.text)
    # image_urls=html.xpath('/html/body/div[5]/ul/li/a/div[1]/img/@src') #图片是js解析出来的,xpath无效,数据在js变量里面
    html=re.compile('lazysrc="https://www.mshxw.com/skin/sinaskin/image/nopic.gif"',re.S)
    image_urls=html.finditer(res.text)

    for url in image_urls:
        res2=requests.get(url.group('img_urls'))
        s=url.group('img_urls')
        i = s.split('.')[2].split('/')[-1]
        with open(f'tupian2/{i}.jpg', mode='wb') as f:  # 写入图片
            f.write(res2.content)

if __name__ == '__main__':
    with ThreadPoolExecutor(20) as t:
        for i in range(1,10):
            t.submit(urls,f'https://www.3gbizhi.com/meinv/index_{i}.html')
    print('下载完成')

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/853856.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号