Selenium 点击进入电影全部影评:Python 代码示例
首先,需要安装 Selenium 库和对应的浏览器驱动程序(如 ChromeDriver),然后通过以下代码实现点击进入电影全部影评的操作:
from selenium import webdriver
# 创建浏览器驱动对象
driver = webdriver.Chrome()
# 打开电影详情页面
driver.get('https://movie.douban.com/subject/1292052/')
# 点击'全部影评'按钮
btn_all_reviews = driver.find_element_by_xpath('//a[@href='reviews']')
btn_all_reviews.click()
这段代码中,driver.get()方法用于访问电影详情页面,driver.find_element_by_xpath()方法用于找到'全部影评'按钮的 XPath 路径,click()方法用于模拟点击操作。执行完这段代码后,浏览器会自动跳转到电影全部影评页面。
原文地址: https://www.cveoy.top/t/topic/oA2J 著作权归作者所有。请勿转载和采集!