首页 > 解决方案 > 抓取时在元素中查找类

问题描述

标签: pythonseleniumweb-scraping

解决方案


使用SeleniumBeautifulSoup

  • findAll是一个BeautifulSoup方法
  • download = driver.find_element_by_xpath('//*[@id="post-22276"]/div/div/p[3]/strong')Selenium WebElement,没有findAll方法。

这是错误的原因。在这里,您如何获得 Selenium 的下载链接:

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

driver = webdriver.Chrome()
wait = WebDriverWait(driver, 10)

driver.get('https://fullmatchsports.co/amiens-vs-psg-full-match-ligue-1-2018/')
# wait until element will be clickable
wait.until(EC.element_to_be_clickable((By.XPATH, '//p[contains(., "Download links")]//a')))

links = driver.find_elements_by_xpath('//p[contains(., "Download links")]//a')

推荐阅读