下载博客园的logo
from urllib.request import urlretrievefrom urllib.request import urlopenfrom bs4 import BeautifulSouphtml = 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