Python网络爬虫

下载博客园的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

原文地址:https://www.cnblogs.com/davidgu/p/4976981.html