使用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裏第二個參數是路徑和名稱。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章