Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python (硒)可以';在Google图像中找不到图像元素超过20个_Python_Selenium_Google Image Search - Fatal编程技术网

Python (硒)可以';在Google图像中找不到图像元素超过20个

Python (硒)可以';在Google图像中找不到图像元素超过20个,python,selenium,google-image-search,Python,Selenium,Google Image Search,我正在尝试使用selenium,chrome驱动程序来抓取google图像 我复制了图像元素的Xpath,并使用了按Xpath查找元素。 但是selenium只能找到页面的前20个图像元素 有没有办法找到更多 代码如下: # -*- coding: utf-8 -*- from selenium import webdriver import urllib.request import time driver = webdriver.Chrome('./chromedriver.exe') d

我正在尝试使用selenium,chrome驱动程序来抓取google图像

我复制了图像元素的Xpath,并使用了按Xpath查找元素。 但是selenium只能找到页面的前20个图像元素

有没有办法找到更多

代码如下:

# -*- coding: utf-8 -*-
from selenium import webdriver
import urllib.request
import time

driver = webdriver.Chrome('./chromedriver.exe')
driver.set_window_size(800, 600)
driver.implicitly_wait(5)
driver.get('https://www.google.com/search?q=a+dog&tbm=isch&ved=2ahUKEwi-59_iiZ_oAhWCIZQKHTaWB5MQ2-cCegQIABAA&oq=a+dog&gs_l=img.3..0l5j0i7i30l5.29034.29325..29590...0.0..0.130.258.0j2......0....1..gws-wiz-img.10szHAao5lM&ei=5ntvXr7cNoLD0AS2rJ6YCQ')

for i in range(1, 10):
     driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
     time.sleep(1)

for i in range(1,100):
    img = driver.find_element_by_xpath('//*[@id="islrg"]/div[1]/div[' +str(i) +']/a[1]/div[1]/img')
    print(img)
    src = img.get_attribute('src')
    print(src)
    urllib.request.urlretrieve(src, "./dog/" + str(i) +".png")



driver.close()

如果脚本“options.add_argument(“--headless”)”中有此类代码,请对其进行注释,然后再次运行,将弹出一个chrome浏览器,您将看到图像仅按页面分组