无需滚动即可下载图像

2024-06-16 09:56:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从谷歌图片下载100多张图片,避免滚动。我已经搜索了几个选项,但对于我的代码,我得到了一个TimeOutException,我不知道为什么。

我加载一个结果页面,然后我搜索按钮“加载更多”(CSS ID=smb)并尝试点击它。你知道吗

from selenium.webdriver.support import ui
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException

url = "https://www.google.com/search?q=table&tbm=isch&source=lnt&tbs=sur:fc&sa=X&ved=0ahUKEwjVgKaq097gAhW7TBUIHd47DvkQpwUIIA&biw=1280&bih=933&dpr=1"

driver = webdriver.Firefox()
page=driver.get(url)
try:
    mySelectElement = WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "smb")))
    print(len(driver.page_source))
    mySelectElement.click()
except TimeoutException as ex:
    isrunning = 0
    print("Exception has been thrown. " + str(ex))
    driver.close()
    pass  

如果能得到任何反馈就太好了!你知道吗

谢谢!你知道吗


Tags: fromimportiduisupportbyasdriver