下载博客园的logo
from urllib.request import urlretrieve from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("http://www.cnblogs.com") bsObj = BeautifulSoup(html, "html.parser") imageLocation = bsObj.find("div", {"id": "logo"}).find("img")["src"] urlretrieve (imageLocation, "blog_logo.jpg")
运行结果:
下载博客园的logo另存为图片文件blog_logo.jpg
时间: 2024-10-05 04:07:57