【发布时间】:2021-09-26 07:45:37
【问题描述】:
我想从网站上抓取产品链接(675 个产品)。第一页只有 24 个带有“显示下一个 23”按钮的产品。我尝试了两种方法来加载更多产品,以便获取它们的链接。
from selenium import webdriver
from selenium.common.exceptions import TimeoutException, NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)
driver.get('https://www.3m.com.au/3M/en_AU/p/c/medical')
while True:
try:
more_button = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'MMM--
btn MMM--btn_tertiary MMM--btn_noAnimation js-pageLoader wt-link wtLoaded mix-
MMM--btn_allCaps'))).click()
except TimeoutException:
break
我也试过
more_button = wait.until(EC.visibility_of_element_located((By.XPATH,'
//*@id="pageContent"]/div[3]/div/div/div[3]/div[5]/div[2]/div[3]/div/div[2]/
div[2]/a'))).click()
但是这两种方法都无法点击“SHOW NEXT 24”按钮。我相信错误 403-forbidden 不会让我加载更多产品。
任何提示或解决方案将不胜感激。提前致谢。
【问题讨论】:
-
看我的回答。请让我知道它是否有效。
标签: python selenium web-scraping