我正试图通过观看此视频的教程来刮取谷歌的图像。 https://www.youtube.com/watch?v=ZAUNEEtzsrg&t=859s
但我在此处发现的是,我的代码无法与视频获得相同的结果。 我的意思是我的结果必须表明&imgres?imgurl'这样我就可以访问图像的原始链接。但是没有什么?imgurl'在我的结果中。
import urllib
import mechanize
from bs4 import BeautifulSoup
from urlparse import urlparse
def getPic(search):
try:
browser = mechanize.Browser()
browser.set_handle_robots(False)
browser.addheaders = [('User-agent','Mozilla')]
htmltext = browser.open("https://www.google.co.kr/search?site=&tbm=isch&source=hp&biw=1204&bih=673&q=cars&oq=cars&gws_rd=cr&ei=Z6XrWOryEMia8QX7x5aYCg")
img_urls = []
formatted_images = []
soup = BeautifulSoup(htmltext, "html.parser")
results = soup.findAll("a")
print results
except:
print "error"
getPic("occupy wall street")
我的结果如下:
[<a class="gbzt" href="https://www.google.co.kr/search?tab=iw" id="gb_1" onclick="gbar.logger.il(1,{t:1});"><span class="gbtb2"></span><span class="gbts">\xb0\xcb\xbb\xf6</span></a>, <a class="gbzt gbz0l gbp1" href="https://www.google.co.kr/imghp?hl=ko&tab=ii" id="gb_2" onclick="gbar.logger.il(1,{t:2});"><span class="gbtb2"></span><span class="gbts">\xc0\xcc\xb9\xcc\xc1\xf6</span></a>, <a class="gbzt" href="https://maps.google.co.kr/maps?hl=ko&tab=il" id="gb_8" onclick="gbar.logger.il(1,{t:8});"><span class="gbtb2"></span><span class="gbts">\xc1\xf6\xb5\xb5</span></a>, <a class="gbzt" href="https://play.google.com/?hl=ko&tab=i8" id="gb_78" onclick="gbar.logger.il(1,{t:78});"><span class="gbtb2"></span><span class="gbts">Play</span></a>, <a class="gbzt" href="https://www.youtube.com/results?gl=KR&tab=i1" id="gb_36" onclick="gbar.logger.il(1,{t:36});"><span class="gbtb2"></span><span class="gbts">YouTube</span></a>, <a class="gbzt" href="https://news.google.co.kr/nwshp?hl=ko&tab=in" id="gb_5" onclick="gbar.logger.il(1,{t:5});"><span class="gbtb2"></span><span class="gbts">\xb4\xba\xbd\xba</span></a>, <a class="gbzt" href="https://mail.google.com/mail/?tab=im" id="gb_23" onclick="gbar.logger.il(1,{t:23});"><span class="gbtb2"></span><span class="gbts">Gmail</span></a>, <a class="gbzt" href="https://drive.google.com/?tab=io" id="gb_49" onclick="gbar.logger.il(1,{t:49});"><span class="gbtb2"></span><span class="gbts">\xb5\xe5\xb6\xf3\xc0\xcc\xba\xea</span></a>, <a aria-haspopup="true" aria-owns="gbd" class="gbgt" href="https://www.google.co.kr/intl/ko/options/" id="gbztm" onclick="gbar.tg(event,this)"><span class="gbtb2"></span><span class="gbts gbtsa" id="gbztms"><span id="gbztms1">\xb4\xf5\xba\xb8\xb1\xe2</span><span class="gbma"></span></span></a>, <a class="gbmt" href="https://www.google.com/calendar?tab=ic" id="gb_24" onclick="gbar.logger.il(1,{t:24});">\xc4\xb6\xb8\xb0\xb4\xf5</a>, <a class="gbmt" href="https://translate.google.co.kr/?hl=ko&tab=iT" id="gb_51" onclick="gbar.logger.il(1,{t:51});">\xb9\xf8\xbf\xaa</a>, <a class="gbmt" href="https://www.google.co.kr/search?hl=ko&tbo=u&tbm=bks&source=og&tab=ip" id="gb_10" onclick="gbar.logger.il(1,{t:10});">\xb5\xb5\xbc\xad</a>, <a class="gbmt" href="https://www.blogger.com/?tab=ij" id="gb_30" onclick="gbar.logger.il(1,{t:30});">Blogger</a>, <a class="gbmt" href="https://photos.google.com/?tab=iq&pageId=none" id="gb_31" onclick="gbar.logger.il(1,{t:31});">\xbb\xe7\xc1\xf8</a>, <a class="gbmt" href="https://www.google.co.kr/search?hl=ko&tbo=u&tbm=vid&source=og&tab=iv" id="gb_12" onclick="gbar.logger.il(1,{t:12});">\xb5\xbf\xbf\xb5\xbb\xf3</a>, <a class="gbmt" href="https://docs.google.com/document/?usp=docs_alc" id="gb_25" onclick="gbar.logger.il(1,{t:25});">\xb9\xae\xbc\xad</a>, <a class="gbmt" href="https://www.google.co.kr/intl/ko/options/" onclick="gbar.logger.il(1,{t:66});">\xb8\xf0\xb5\xce \xba\xb8\xb1\xe2</a>, <a class="gbgt" href="https://accounts.google.com/ServiceLogin?hl=ko&passive=true&continue=https://www.google.co.kr/search%3Fsite%3D%26tbm%3Disch%26source%3Dhp%26biw%3D1204%26bih%3D673%26q%3Dcars%26oq%3Dcars%26gws_rd%3Dcr%26ei%3DZ6XrWOryEMia8QX7x5aYCg" id="gb_70" onclick="gbar.logger.il(9,{l:'i'})" target="_top"><span class="gbtb2"></span><span class="gbts" id="gbgs4"><span id="gbi4s1">\xb7\xce\xb1\xd7\xc0\xce</span></span></a>, <a aria-haspopup="true" aria-owns="gbd5" class="gbgt" href="http://www.google.co.kr/preferences?hl=ko" id="gbg5" onclick="gbar.tg(event,this)" title="\xbf\xc9\xbc\xc7"><span class="gbtb2"></span><span class="gbts" id="gbgs5"><span id="gbi5"></span></span></a>, <a class="gbmt" href="/preferences?hl=ko">\xb0\xcb\xbb\xf6 \xc8\xaf\xb0\xe6\xbc\xb3\xc1\xa4</a>, <a class="gbmt" href="http://www.google.co.kr/history/optout?hl=ko">\xc0\xa5 \xb1\xe2\xb7\xcf</a>, <a href="/webhp?hl=ko" id="logo" style="background:url(/images/nav_logo229.png) no-repeat 0 -41px;height:37px;width:95px;display:block" title="Go to Google Home"></a>, <a class="_UXb _Jhd _Hhd" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&source=lnms&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQ_AUIBA">\xc0\xfc\xc3\xbc</a>, <a class="_UXb _Jhd" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=vid&source=lnms&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQ_AUIBg">\xb5\xbf\xbf\xb5\xbb\xf3</a>, <a class="_UXb _Jhd" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=nws&source=lnms&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQ_AUIBw">\xb4\xba\xbd\xba</a>, <a class="_UXb _Jhd" href="https://maps.google.co.kr/maps?biw=1204&bih=673&q=cars&gws_rd=cr&um=1&ie=UTF-8&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQ_AUICA">\xc1\xf6\xb5\xb5</a>, <a class="_UXb _Jhd" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=bks&source=lnms&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQ_AUICQ">\xb5\xb5\xbc\xad</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=isz:l&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc5\xab \xbb\xe7\xc0\xcc\xc1\xee</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=isz:m&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc1\xdf\xb0\xa3 \xbb\xe7\xc0\xcc\xc1\xee</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=isz:i&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xbe\xc6\xc0\xcc\xc4\xdc</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=ic:color&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc4\xae\xb6\xf3</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=ic:gray&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc8\xe6\xb9\xe9</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=ic:trans&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc5\xf5\xb8\xed</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=itp:face&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xbe\xf3\xb1\xbc</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=itp:photo&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xbb\xe7\xc1\xf8</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=itp:clipart&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc5\xac\xb8\xb3\xbe\xc6\xc6\xae</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=itp:lineart&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xb6\xf3\xc0\xce\xbe\xc6\xc6\xae</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=itp:animated&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xbe\xd6\xb4\xcf\xb8\xde\xc0\xcc\xbc\xc7</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=qdr:d&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg"> \xc1\xf6\xb3\xad 1\xc0\xcf</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=qdr:w&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg"> \xc1\xf6\xb3\xad 1\xc1\xd6</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=sur:fmc&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xbc\xf6\xc1\xa4 \xc8\xc4 \xc0\xe7\xbb\xe7\xbf\xeb \xb0\xa1\xb4\xc9</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=sur:fc&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xc0\xe7\xbb\xe7\xbf\xeb \xb0\xa1\xb4\xc9</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=sur:fm&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xbc\xf6\xc1\xa4 \xc8\xc4 \xba\xf1\xbb\xf3\xbe\xf7\xc0\xfb \xbf\xeb\xb5\xb5\xb7\xce \xc0\xe7\xbb\xe7\xbf\xeb \xb0\xa1\xb4\xc9</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&source=lnt&tbs=sur:f&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQpwUIDg">\xba\xf1\xbb\xf3\xbe\xf7\xc0\xfb \xbf\xeb\xb5\xb5\xb7\xce \xc0\xe7\xbb\xe7\xbf\xeb \xb0\xa1\xb4\xc9</a>, <a class="q" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&tbas=0&sa=X&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQuAsIDw" style="padding-left:16px">\xb5\xb5\xb1\xb8 \xc3\xca\xb1\xe2\xc8\xad</a>, <a href="/url?q=http://droom.in/car&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IFTAA&usg=AFQjCNFJZ34GAgWZ56WgBxTQ0Jmxq2KoLQ"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="91" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSQdrZhb4NyNuKkLHdO1wT8U51zpsvztBT3X3kW_2EGrowyaBdDkeqW3uA" width="129"/></a>, <a href="/url?q=http://www.caranddriver.com/features/2017-10best-cars-the-best-cars-for-sale-in-america-today-feature&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IFzAB&usg=AFQjCNHBU3fAqKGGBteYiP1eSPI-H4N-uQ"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="89" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQr3frVY4p6BYk0tORsu2le-6pGdFD73JshLUxjWigidyWyjUMkZOFfcQw2" width="145"/></a>, <a href="/url?q=http://www.car.com/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IGTAC&usg=AFQjCNGW3nkf73r24x8j0Six1FRhC059pw"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="97" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcS985vI2ClgxX0vEXZdSMiStWUkeMtkg0IXIjrtRMoY2MGYR_kZy6k56ko" width="146"/></a>, <a href="/url?q=https://www.whichcar.com.au/car-style/12-cartoon-cars&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IGzAD&usg=AFQjCNEVjMqjVC3AB2kuGqZWHDbQxjtezw"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="92" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSVixNz-pL5YOLScxcGMgvp0QyUtB-a4oGtTd-5_7Ytf8GW3_a7XdbhTQVf" width="138"/></a>, <a href="/url?q=https://www.tes.com/lessons/oWgzk4OrhaNTGg/cars-and-games&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IHTAE&usg=AFQjCNFbOZXvvPAP6PxcIdQNjyDEOQxeAg"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="84" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQ8zH6wSHea6FT0cAqVUiDBn5u4E5heQFPvl4DxApkOZdn-LbZseRSb02rF" width="150"/></a>, <a href="/url?q=http://www.caranddriver.com/features/25-cars-worth-waiting-for-20162019-feature&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IHzAF&usg=AFQjCNHCvz_P5ISR63m9DWMlPBlWwrGnzA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="92" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRIii0QfouEcUjpeQhejnQ9pK6LcgEqWauvAX7yFhZXDQ4e9OYU24PcrmHY" width="150"/></a>, <a href="/url?q=https://pixabay.com/en/photos/cars/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IITAG&usg=AFQjCNG6uALkSPojRhp7j0a6Kek3RDcftw"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="83" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTZw2B9fsnAwlogi_4OEq_I9-Hv_yQA_M5XAhhCT3IG0fGdqg9LV80-dGIQ" width="148"/></a>, <a href="/url?q=http://www.caranddriver.com/features/2017-editors-choice-for-best-cars-trucks-crossovers-and-suvs&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IIzAH&usg=AFQjCNHLez5RDNIp1CMh6ANfe8k57ejzDw"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="87" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQWrDa3hXOx8yea5Fn45lDzXQFXqCX-qlvT7gHAsDk3LjRt39r6K9i5sBY" width="143"/></a>, <a href="/url?q=https://www.pinterest.com/explore/cars/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IJTAI&usg=AFQjCNFYwvgJpW9S7Tj3yoxD5QOxSfssnw"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="150" src="https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQZnu1shU3UB0UoYe1XCUNwh50duFPtYmGPuI6hHzOP1wiicynZaELRsIhA" width="100"/></a>, <a href="/url?q=http://www.businessinsider.com/new-cars-2016-la-auto-show-pictures-2016-11&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IJzAJ&usg=AFQjCNGbI00EPtx2Ln366KRhiF1PeNfsnA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="113" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRTj7kkhCCesjW7bSkS_bQ4XwBRHgyzUWxlapXv2zPMklJm3tzXrjF5ONPq" width="150"/></a>, <a href="/url?q=https://www.pinterest.com/explore/car-pictures/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IKTAK&usg=AFQjCNGXGpILFRjefrtxKHoH48d4d1s-9g"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="84" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTz_ikUlL6-erXMyLFkAirt3lA8layg-DoTKAyVF4QElHVw8Upddn9gGpw" width="150"/></a>, <a href="/url?q=https://www.avis.co.za/drive-avis/fleet&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IKzAL&usg=AFQjCNEgN171ioFWaWFl08mwIuKDHSkYzA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="69" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcR7Dhmz6Fth4uM6TNPN8ZTswwElqhS53ENNB9ykgB3hn9viuC-l3uaIr58" width="142"/></a>, <a href="/url?q=https://www.pexels.com/search/car/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4ILTAM&usg=AFQjCNE41b5NXnZWZ08z4rQSI0ss396hVg"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="100" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcQO4vSCA-MwM6Vp1r-WY1VSVC-zlUDEAAc_eMIBPsmCvakzOY3XzfemNnDF" width="150"/></a>, <a href="/url?q=http://www.autotrader.co.za/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4ILzAN&usg=AFQjCNFCa-E-Lmvjdu8sTGOwkzIpRx6PqQ"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="46" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQMcOhmOZrTbMEnZE7LnKORwT7QdybnOUCwmq7Op4JDWz3-Jgu3LPB3AvCA" width="149"/></a>, <a href="/url?q=https://www.enterprise.com/en/car-rental/vehicles/us.html&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IMTAO&usg=AFQjCNGmp-_mq9toGDv_g6EKElCnIh5paA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="107" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRrZQa7YIHJbxbZYpDNv6cRBICOqucSV51g3gDHTB6e6CUn-SD8xN8mZik" width="143"/></a>, <a href="/url?q=http://kingofwallpapers.com/cars.html&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IMzAP&usg=AFQjCNEIsll5cQ__ljEQrlXnhKN0Sy5MZA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="94" src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQEKolof015oYI_P_MButmQAQY4lvdPCFqqUEBl0lV5eq54nSD7VVu3_X4" width="150"/></a>, <a href="/url?q=https://www.pexels.com/photo/car-cars-lamborghini-aventador-luxury-car-63764/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4INTAQ&usg=AFQjCNE88-oCWsmAeYPEt1_8Cuas65u2IA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="88" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSzK4-EvkVaqJg1OP_owFMJDpKJzAhWH_ZEHCX5CnDLdh6Qg5b_PMCKSp58" width="150"/></a>, <a href="/url?q=http://wallpaperswide.com/cars-desktop-wallpapers.html&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4INzAR&usg=AFQjCNGIyj5EW6Lh9QTeKDdh13JjpLEAtw"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="94" src="https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcTBrhBy0oX1z3eBnLCc13oQLGKctyFbkSIFHt8XgW5fKx01bZySoqFF4IE" width="150"/></a>, <a href="/url?q=https://gearpatrol.com/cars/&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IOTAS&usg=AFQjCNFb5A1Q0IcxyCasVeMqErmzXT9MkQ"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="105" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRqbpIywaSd-3-GLHdG4sXCqec_xKiIK4vvXkS9nkdi_-2H_IHEqSGnaVw4" width="137"/></a>, <a href="/url?q=http://www.caranddriver.com/features/25-cars-worth-waiting-for-20162019-feature&sa=U&ved=0ahUKEwjIoIvsnZrTAhXMi7wKHU8LDFwQwW4IOzAT&usg=AFQjCNHCvz_P5ISR63m9DWMlPBlWwrGnzA"><img alt="cars\xbf\xa1 \xb4\xeb\xc7\xd1 \xc0\xcc\xb9\xcc\xc1\xf6 \xb0\xcb\xbb\xf6\xb0\xe1\xb0\xfa" height="92" src="https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQf_kKvSclRQiW7MCKi6AjqYt-P0Pyed6LlxyRIbCooMNmKerovfpUFkgI" width="150"/></a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=20&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>2</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=40&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>3</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=60&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>4</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=80&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>5</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=100&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>6</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=120&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>7</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=140&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>8</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=160&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>9</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=180&sa=N"><span class="csb" style="background-position:-74px 0;width:20px"></span>10</a>, <a class="fl" href="/search?q=cars&biw=1204&bih=673&ie=UTF-8&tbm=isch&ei=m6jrWIjnLsyX8gXPlrDgBQ&start=20&sa=N" style="text-align:left"><span class="csb" style="background-position:-96px 0;width:71px"></span><span style="display:block;margin-left:53px">\xb4\xd9\xc0\xbd</span></a>, <a href="https://www.google.co.kr/advanced_image_search?biw=1204&bih=673&q=cars&gws_rd=cr&tbm=isch">\xb0\xed\xb1\xde\xb0\xcb\xbb\xf6</a>, <a href="https://www.google.co.kr/imghp?hl=ko">Google \xc0\xcc\xb9\xcc\xc1\xf6 \xc8\xa8</a>, <a href="http://images.google.com/support/?hl=ko">\xb5\xb5\xbf\xf2\xb8\xbb</a>, <a href="/tools/feedback/survey/html?productId=196&hl=ko&query=cars">\xc0\xc7\xb0\xdf \xba\xb8\xb3\xbb\xb1\xe2</a>, <a href="/">Google\xa0\xc8\xa8</a>, <a href="/intl/ko/ads">Google \xb1\xa4\xb0\xed \xc7\xc1\xb7\xce\xb1\xd7\xb7\xa5</a>, <a href="/intl/ko/policies/privacy/">\xb0\xb3\xc0\xce\xc1\xa4\xba\xb8\xc3\xb3\xb8\xae\xb9\xe6\xc4\xa7</a>, <a href="/intl/ko/policies/terms/">\xbe\xe0\xb0\xfc</a>, <a href="/intl/ko/about.html">Google \xc1\xa4\xba\xb8</a>]
答案 0 :(得分:1)
这是因为该教程已经过时(从2013年开始),Google Images的HTML从那时起就发生了变化。
尝试使用Firebug / Firepath创建XPATH / CSS Selector或id / class并进行调试。
我刚看了一下源代码,我认为你可以按班级rg_ic rg_i
选择所有图片。
答案 1 :(得分:0)
点击原始尺寸 img
的链接会出现。您可以使用 selenium
来模拟点击。
Steps:
1. Click on the image,
2. Inspect the image on the right,
3. Scrape src attribute for full-size image.
4. Create a for loop to grab other images.
另一种方法是使用 regex
解析它:
import requests, lxml, re
from bs4 import BeautifulSoup
headers = {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 Safari/537.36 Edg/79.0.309.43"
}
params = {"q": "london", "tbm": "isch"}
html = requests.get("https://www.google.com/search",
params=params,
headers=headers).text
soup = BeautifulSoup(html, 'lxml')
# https://regex101.com/r/vO7WsC/5
pattern = re.compile(
r'\[1,\[0,"(?P<id>[\d\w\-_]+)",\["https?:\/\/(?:[^"]+)",\d+,\d+\]\s?,\["(?P<url>https?:\/\/(?:[^"]+))",\d+,\d+\]'
)
images = dict(pattern.findall(html))
for image_node in soup.select('.BUooTd[data-id]'):
title = image_node.select_one('.WGvvNb')['title']
image = images[image_node['data-id']]
print(f"Title: {title}\nOriginal image: {image}\n")
输出:
Title: London - Wikipedia
Original image: https://upload.wikimedia.org/wikipedia/commons/c/cd/London_Montage_L.jpg
Title: London: A History - HISTORY
Original image: https://www.history.com/.image/ar_1:1%2Cc_fill%2Ccs_srgb%2Cfl_progressive%2Cq_auto:good%2Cw_1200/MTYyNDg1MjE3MTI1Mjc5Mzk4/topic-london-gettyimages-760251843-promo.jpg
Title: City of London - Wikipedia
Original image: https://upload.wikimedia.org/wikipedia/commons/8/86/City_of_London%2C_seen_from_Tower_Bridge.jpg
Title: London - Wikipedia
Original image: https://upload.wikimedia.org/wikipedia/commons/thumb/e/e4/Palace_of_Westminster_from_the_dome_on_Methodist_Central_Hall_%28cropped%29.jpg/1000px-Palace_of_Westminster_from_the_dome_on_Methodist_Central_Hall_%28cropped%29.jpg
或者,您可以使用来自 SerpApi 的 Google Images API 获取原始大小的 Google 图片。这是一个免费试用的付费 API。
from serpapi import GoogleSearch
import os
params = {
"engine": "google",
"ijn": "0",
"q": "cars",
"tbm": "isch",
"api_key": os.getenv("API_KEY"),
}
search = GoogleSearch(params)
results = search.get_dict()
for image in results['images_results']:
print(f"Title: {image['title']}\nSource: {image['source']}\nOriginal Image: {image['original']}\n")
完整输出的一部分:
Title: Best Opening Races From Pixar's Cars! | Pixar Cars - YouTube
Source: youtube.com
Original Image: https://i.ytimg.com/vi/L9ZYdShgtPE/maxresdefault.jpg
Title: Cars (film) - Wikipedia
Source: en.wikipedia.org
Original Image: https://upload.wikimedia.org/wikipedia/en/3/34/Cars_2006.jpg
Title: Official Trailer: Cars (2006) - YouTube
Source: youtube.com
Original Image: https://i.ytimg.com/vi/SbXIj2T-_uk/maxresdefault.jpg
<块引用>
免责声明,我为 SerpApi 工作。