python爬取壁纸,简单例程

[复制链接]
查看691 | 回复4 | 2020-4-8 22:14:45 | 显示全部楼层 |阅读模式
[/free]from urllib import request  #从urllib库里导入request模块
from bs4 import BeautifulSoup   #从BeautifulSoup4(bs4)库里导入BeautifulSoup模块
import re   #导入正则表达式模块re模块
import time     #导入time模块

url = "https://www.zhihu.com/question/64252714"
html = request.urlopen(url).read().decode('utf-8')
soup = BeautifulSoup(html, 'html.parser')


links = soup.find_all('img', 'origin_image zh-lightbox-thumb', src = re.compile(r'jpg$'))
print(links)

path = r'E:\文章\5S分辨率\images'  
    #保存到某个文件夹下
for link in links:
    print(link.attrs['src'])
    request.urlretrieve(link.attrs['src'], path + '\%s.jpg' % time.time())
[free]
购买主题 本主题需向作者支付 1 枚金币 才能浏览
回复

使用道具 举报

longxuekai | 2020-4-9 06:29:41 | 显示全部楼层
回复

使用道具 举报

wangy2000 | 2020-4-9 07:59:22 | 显示全部楼层
回复

使用道具 举报

郑先生 | 2020-4-9 08:06:20 | 显示全部楼层
回复

使用道具 举报

kingboy100 | 2020-4-9 08:09:40 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则