尝试在python中使用selenium从网站“www.example.com“的导航栏单击”下一步“按钮https://uk.trustpilot.com/categories/bars_cafes?subcategories=cafe。
from selenium.webdriver import Chrome
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import time
URL = "https://uk.trustpilot.com/categories/bars_cafes?subcategories=cafe"
driver = Chrome(ChromeDriverManager().install())
class Scraper:
def __init__(self, website):
self.website = website
def get_website(self):
return driver.get(self.website)
def ignore_cookie(self):
try:
ignore_cookies = driver.find_element(by=By.XPATH, value='//*[@id="onetrust-reject-all- handler"]')
ignore_cookies.click()
except AttributeError:
pass
def next_page(self):
driver.find_element(by=By.NAME, value="pagination-button-next").click()
ignore cookie函数工作正常,但next_page函数滚动到next按钮,但没有点击它。
2条答案
按热度按时间xfyts7mz1#
包括以下导入:
编辑
next_page
函数,如下所示:请参见https://www.selenium.dev/documentation/上的Selenium文档
w8biq8rn2#
这应该可以做到: