使用python爬取一张图片,超简单!

使用python爬取一张图片

from urllib.request import urlretrieve
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com")
bsObj = BeautifulSoup(html)
imageLocation = bsObj.find("a", {"id": "logo"}).find("img")["src"]
urlretrieve (imageLocation, "/Users/phoenix/Downloads/logo.jpg")

在这里插入图片描述
urlretrieve里第二个参数是路径和名称。

发布了11 篇原创文章 · 获赞 38 · 访问量 4232

猜你喜欢

转载自blog.csdn.net/qq_37924224/article/details/105202658