私は私がstackoverflowの答えに、私はどのように詳細に説明します
Python - Download Images from google Image search?
を書いた元のスクリプト私は現在、100元の画像に
をダウンロードGoogle画像検索を形成する画像をダウンロードするためのスクリプトを書きましたurllib2とBeautifulSoupを使ってGoogleの画像検索からURLを取得しています。
たとえば、映画ターミネーターの画像を削りたい場合は3上記メートル、Googleの画像検索
query= "Terminator 3"
query= '+'.join(query.split()) #this will make the query terminator+3
url="https://www.google.co.in/search?q="+query+"&source=lnms&tbm=isch"
header={'User-Agent':"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36"
}
req = urllib2.Request(url,headers=header)
soup= urllib2.urlopen(req)
soup = BeautifulSoup(soup)
変数スープは今、私たちはuは、ブラウザでWebページを開く必要がありますし、そして上の要素を検査行い、そのために画像を抽出する必要が要求されたページのHTMLコードが含まれていますここでは画像
私は「DIV」を見つけ、Googleの画像について、たとえば、{「クラス」:「rg_meta」} URL
の画像を含むタグが見つかります画像へのリンクを含んを
あなたはBeautifulSoup doccummenを検索することができますtation
print soup.find_all("div",{"class":"rg_meta"})
uが
<div class="rg_meta">{"cl":3,"cr":3,"ct":12,"id":"C0s-rtOZqcJOvM:","isu":"emuparadise.me","itg":false,"ity":"jpg","oh":540,"ou":"http://199.101.98.242/media/images/66433-Terminator_3_The_Redemption-1.jpg","ow":960,"pt":"Terminator 3 The Redemption ISO \\u0026lt; GCN ISOs | Emuparadise","rid":"VJSwsesuO1s1UM","ru":"http://www.emuparadise.me/Nintendo_Gamecube_ISOs/Terminator_3_The_Redemption/66433","s":"Screenshot Thumbnail/Media File 1 for Terminator 3 The Redemption","th":168,"tu":"https://encrypted-tbn2.gstatic.com/images?q\\u003dtbn:ANd9GcRs8dp-ojc4BmP1PONsXlvscfIl58k9hpu6aWlGV_WwJ33A26jaIw","tw":300}</div>
結果は、上記の私たちの画像URLへのリンクが含まれているとして、結果のリストを取得します
http://199.101.98.242/media/images/66433-Terminator_3_The_Redemption-1.jpg
を次のようにuはこれらのリンクや画像を抽出することができます
ActualImages=[]# contains the link for Large original images, type of image
for a in soup.find_all("div",{"class":"rg_meta"}):
link , Type =json.loads(a.text)["ou"] ,json.loads(a.text)["ity"]
ActualImages.append((link,Type))
for i , (img , Type) in enumerate(ActualImages):
try:
req = urllib2.Request(img, headers={'User-Agent' : header})
raw_img = urllib2.urlopen(req).read()
if not os.path.exists(DIR):
os.mkdir(DIR)
cntr = len([i for i in os.listdir(DIR) if image_type in i]) + 1
print cntr
if len(Type)==0:
f = open(DIR + image_type + "_"+ str(cntr)+".jpg", 'wb')
else :
f = open(DIR + image_type + "_"+ str(cntr)+"."+Type, 'wb')
f.write(raw_img)
f.close()
except Exception as e:
print "could not load : "+img
print e
出来上がりは今uがあなたが
https://gist.github.com/rishabhsixfeet/8ff479de9d19549d5c2d8bfc14af9b88
ここでそれを得ることができGoogle検索
からか、完全に動作するスクリプトのためのトレーニング画像に
を収集するための画像をダウンロードするには、このスクリプトを使用することができますあなたはGoogleのを見たことがありますあなたがすべて(何百万もの可能性があります)結果を与える - 結果ページ?ただし、image-search-api:http://code.google.com/intl/de/apis/imagesearch/ –
はいDr.Mollieを使用することをおすすめします。しかし、それが戻ってくると、それらの一部だけが返されます。すべてではない。我々はGoogleの画像をスクラップすることはできません。 –
すべての結果(もちろん20枚以上の画像)を含むこれらの結果ページの1つを表示してください –