gpt4 book ai didi

python - 如何在selenium中单击加载更多按钮直到页面结束python?

转载 作者:行者123 更新时间:2023-12-01 00:45:09 26 4
gpt4 key购买 nike

使用selenium加载和分页,需要单击“加载更多”按钮,但无法做到这一点。

尝试过这个:

from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome('/Users/1/chromedriver.exe')
driver.get('https://simpletire.com/catalog?select=1&brand=61&query=catalog')

driver.find_element_by_css_selector(".btn.btn-primary.btn-lg").click();

尝试了上面的方法,但是单击按钮并且有多个加载更多如何加载它们多次直到页面结束

错误:

试图让它保持循环但得到:

element not interactable

最佳答案

对我有用的解决方案有点简单,需要一点努力,但效果很好。

count=20
while count>1:
button=driver.find_element_by_css_selector("button.ipl-load-more__button")
button.click()
count-=1
time.sleep(2)
//do you work once all the pages are loaded

您唯一需要担心的是设置正确的计数值,如果它太小,您可能会抛出错误,只需捕获它并根据您的要求增加/减少计数值即可。我希望这会有所帮助。

关于python - 如何在selenium中单击加载更多按钮直到页面结束python?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57034918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com