selenium 操作

发布时间:2026/6/24 10:59:37

selenium 操作 使用selenium写基本的爬虫程序import time from selenium import webdriver from selenium.webdriver.chrome.service import Service from webdriver_manager.chrome import ChromeDriverManager js_code window.open({}); # 指定chromedriver的路径 sevice Service(executable_path./chromedriver.exe) #创建浏览器对象 browser webdriver.Chrome(serviceService(ChromeDriverManager().install())) list_data [] browser.get(https://movie.douban.com/top250) #访问测试 def get_data(page): url https://movie.douban.com/top250?start{}filter.format(page*25) browser.execute_script(js_code.format(url)) print(正在爬取第{}页数据.format(page1),url) list1 browser.find_elements(byxpath, value//div[classhd]/a/span[1]) for i in list1: list_data.append(i.text) for i in range(10): get_data(i) time.sleep(1) print(list_data) browser.quit()

相关新闻