資源簡介
python爬取百度圖片,通過更改標簽名,可以爬取各種類型的圖片,如動物,水果,美女,動漫等等,還可以通過更改格式來保證下載的圖片格式一致。還有圖像批量處理程序是統(tǒng)一爬取圖片的分辨率,名稱,格式。
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
Created?on?Tue?Feb?19?08:12:56?2019
@author:?ZTT
“““
#?-*-?coding:?utf-8?-*-
“““
Created?on?Sat?Feb?16?15:54:43?2019
@author:?ZTT
“““
import?requests
from?bs4?import?BeautifulSoup
import?os
def?getHtmlurl(url):?????????#獲取網(wǎng)址
????try:
???????r=requests.get(url)
???????r.raise_for_status()
???????r.encoding=r.apparent_encoding
???????return?r.text
????except:
????????return?““
def?getpic(html):?#獲取圖片地址并下載
????soup?=BeautifulSoup(html‘html.parser‘)
????all_img=soup.find(‘ul‘class_=‘pli‘).find_all(‘img‘)
????for?img?in?all_img:
???????src=img[‘src‘]
???????img_url=src
???????print?(img_url)
???????root=‘D:/E/‘
???????path?=?root?+?img_url.split(‘/‘)[-1]
???????try:??????????????????????????????#創(chuàng)建或判斷路徑圖片是否存在并下載
??????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????806??2019-02-25?17:00??圖片批量處理(大小,格式)\change.py
?????文件???????1786??2019-02-19?08:14??python爬取百度圖片\collect.py
?????目錄??????????0??2019-02-19?08:15??圖片批量處理(大小,格式)
?????目錄??????????0??2019-02-19?08:14??python爬取百度圖片
-----------?---------??----------?-----??----
?????????????????2592????????????????????4
評論
共有 條評論