此文仅做记录,方便自己观看
import requests
from bs4 import BeautifulSoup
url = "https://www.agefans.tv/update"
r = requests.get(url)
print(r.status_code)
r.encoding = r.apparent_encoding
text = r.text
soup = BeautifulSoup(text,"html.parser")
a_nav = soup.find_all('img')
for l in a_nav:
link_jpg = l.attrs['src']
url_pic = 'https:' + link_jpg
# print(url_pic)
get_url = requests.get(url_pic)
path = "D://y_get_pictures//pictures" +url_pic.split('/')[-1]
with open(path, 'wb') as f:
f.write(get_url.content)
f.close()
#图片的URL:
# https://wxt.sinaimg.cn/large/6e6880degy1g6xxndimfjj204605smxa.jpg
本文介绍了一个使用Python的requests库和BeautifulSoup库实现的自动化图片爬取脚本。该脚本从指定网站抓取图片链接,并将图片下载到本地指定路径。通过解析网页源代码,定位到包含图片链接的元素,然后遍历这些元素获取图片的URL,最后下载并保存图片。
4547

被折叠的 条评论
为什么被折叠?



