【爬蟲】網頁圖片爬蟲工具——從谷歌必應上爬取圖片


 

最近需要從谷歌和必應上爬一批圖片,但是基於不同網站有不同的規則,所以對於我這個爬蟲小白來說,URL以及正則化表達式的理解和查改就很困難。

后來在github上發現了很好用的工具,簡便快捷,正好分享給大家。

1.從谷歌上爬取圖片數據——google-images-download

   https://github.com/hardikvasa/google-images-download

下載圖片的算法邏輯結構:

  

安裝使用非常簡單,可以使用以下幾個方法之一進行安裝:


  •   使用pip安裝:
    pip install google_images_download

     

  • 使用CLI安裝:
    git clone https://github.com/hardikvasa/google-images-download.git
    cd google-images-download && sudo python setup.py install

     

  • 手動下載安裝:
    轉到Github上的repo=>
    單擊“Clone or Download”==>
    單擊“Download ZIP”並將其保存到本地磁盤上

 

 

安裝或下載好之后,進行圖片的爬取:


  • 如果是使用pip或者CLI安裝,使用如下命令進行操作:
    googleimagesdownload [Arguments...]
  • 如果是通過用戶自己下載的方式,首先解壓下載的文件,進入'google_images_download'目錄下,使用如下命令進行操作:
    python3 google_images_download.py [Arguments...]
    

    或者

    python google_images_download.py [Arguments...]

 

 

 

常見的參數及命令如下所示:

  • 如果要從配置文件中傳遞參數,只需使用JSON文件名進行配置文件的參數傳遞即可:
    googleimagesdownload -cf example.json

     

  • 只使用關鍵字和限制參數的簡單示例:
    googleimagesdownload --keywords "Polar bears, baloons, Beaches" --limit 20

     

  • 使用后綴關鍵字可以在主關鍵字之后指定單詞。例如,如果關鍵字=car,后綴關鍵字=red,blue,則首先搜索car red,然后搜索car blue:
    googleimagesdownload --k "car" -sk 'red,blue,white' -l 10

     

  • 使用速記命令:
    googleimagesdownload -k "Polar bears, baloons, Beaches" -l 20

     

  • 下載具有特定圖像擴展名或格式的圖片:
    googleimagesdownload --keywords "logo" --format svg

     

  • 為圖片使用顏色過濾器:
    googleimagesdownload -k "playground" -l 20 -co red

     

  • 使用非英文的關鍵字對圖片進行搜索:
    googleimagesdownload -k "北極熊" -l 5

     

  • 從谷歌圖片鏈接下載圖片:
    googleimagesdownload -k "sample" -u <google images page URL>

     

  • 在特定主目錄中保存圖片(不是在“下載”中):
    googleimagesdownload -k "boat" -o "boat_new"

     

  • 使用圖像URL下載單個圖像:
    googleimagesdownload --keywords "baloons" --single_image <URL of the images>

     

  • 下載帶有大小和類型約束的圖像:
    googleimagesdownload --keywords "baloons" --size medium --type animated

     

  • 下載具有特定使用權限的圖像:
    googleimagesdownload --keywords "universe" --usage_rights labeled-for-reuse

     

  • 下載具有特定顏色類型的圖像:
    googleimagesdownload --keywords "flowers" --color_type black-and-white

     

  • 下載具有特定縱橫比的圖像:
    googleimagesdownload --keywords "universe" --aspect_ratio panoramic

     

  • 下載與您提供的圖像URL中的圖像類似的圖像:
    googleimagesdownload -si <image url> -l 10

     

  • 從特定網站或域名下載給定關鍵字的圖像:
    googleimagesdownload --keywords "universe" --specific_site example.com

     

 

2.從bing上爬取圖片數據——Bulk-Bing-Image-downloader

   https://github.com/ostrolucky/Bulk-Bing-Image-downloader

 使用非常簡單:


  • 可以git clone或者直接下載到本地
  • 進入文件目錄,直接運行:
    bbid.py [-h] [-s SEARCH_STRING] [-f SEARCH_FILE] [-o OUTPUT]
                   [--adult-filter-on] [--adult-filter-off] [--filters FILTERS]
                   [--limit LIMIT]
  • 舉個例子:
    ./bbid.py -s "hello world"

     

-----------------------持續補充-------------------------

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM