653| 4
|
python爬取壁纸,简单例程 |
[/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 枚金币 才能浏览
《《《 点击这里展开全文 》》》 | |
发表于 2020-4-9 06:29:41
|
显示全部楼层
| |
发表于 2020-4-9 07:59:22
|
显示全部楼层
| |
发表于 2020-4-9 08:06:20
|
显示全部楼层
| |
发表于 2020-4-9 08:09:40
|
显示全部楼层
| |