爬虫

from urllib.request import urlopen, Request
from bs4 import BeautifulSoup
import re
import os
from urllib.request import urlretrieve

url="https://mp.weixin.qq.com/s?__biz=MzA3MjcxMDMyMg==&mid=2247525125&idx=5&sn=c0e6722238e3bbf63d1ac6dd5c769f6a&chksm=9f1802d8a86f8bce37c27629e6ac4a073f3c798712b52f3e1237e453645f0b6a7e44f91e6d17&scene=21#wechat_redirect"
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36'}    
ret = Request(url, headers=headers)    
res = urlopen(ret)    
bs = BeautifulSoup(res,'html.parser')    
til = bs.find_all('a',{"target":"_blank"})

for url in til:
    d=url["href"]
    ret = Request(d, headers=headers)
    res = urlopen(ret)  
    bs = BeautifulSoup(res,'html.parser')
    til = bs.find('meta',{"property":"og:title"})
    strname=til["content"]
    dir=os.path.abspath('d:/')
    dir=dir+strname+"/"
    print(dir)
    os.makedirs(dir)
    img_urls=bs.find_all("img",{"class":"rich_pages js_insertlocalimg"})
    i=1
    for img_url in img_urls:
        print(img_url["data-src"])
        work_path=os.path.join(dir,str(i)+'.jpeg')
        urlretrieve(img_url["data-src"],work_path)
        i=i+1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值