新手小白最近跟朋友合作一個小專案
找到一個用PYTHON 來抓圖的套件

安裝和用法都很簡單
官網: https://github.com/hardikvasa/google-images-download

這邊只是簡單操作一次看看

1.安裝
在 Anaconda Prompt 裡打 

pip install google_images_download

我是這樣就簡單安裝起來了~

2.載入

from google_images_download import google_images_download   #importing the library
 

3.操作

response = google_images_download.googleimagesdownload()  
#keywords 打要搜尋的關鍵字
arguments = {"keywords":"tree,dog","limit":2,"print_urls":True}    # limit 就是設定最多抓幾張  print_urls 只是要不要記錄圖檔路徑而已

#雖然我打了兩個關鍵字 但他實際上執行兩次抓圖
#一次抓樹 一次抓狗 然後放在兩個不同的資料夾
paths = response.download(arguments)  
print(paths)   #printing absolute paths
##下圖是執行後的結果
## Image URL 就是該圖檔的下載路徑 我limit設2 所以執行兩次

4.輸出

執行完上面的步驟後
他會在你的程式路徑 生出一個 downloads 的資料夾
 

打開後 會有我剛搜的 tree 和 dog 

點開後就得到我要的圖囉~

狗狗還真可愛^^ 

5.讀圖

#### 要把剛剛載下來的圖用PYTHON 畫出來可以試試 以下辦法

%matplotlib

from PIL import Image
import matplotlib.pyplot as plt
img=Image.open('C:/Users/Mrter/Desktop/Pythontest/get_imageV1/downloads/dog/1. maxresdefault.jpg')
plt.figure("dog")
plt.imshow(img)
plt.show()

### 下圖為我們讀出來的結果 圖片會開在另一個視窗

 

arrow
arrow
    文章標籤
    新手 小白 python 入門
    全站熱搜

    Markjong001 發表在 痞客邦 留言(0) 人氣()