采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
def disabled_lazy_load(): driver = None try: chromedriver_path = f"{os.getcwd()}/src/chromedriver" service = Service(chromedriver_path) prefs = { "profile.managed_default_content_settings.images": 2 # 禁用所有图片加载 } options = Options() options.add_experimental_option("prefs", prefs) driver = webdriver.Chrome(service=service, options=options) driver.get('https://www.bilibili.com/') WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.CLASS_NAME, "feed-card"))) element = driver.find_element(By.CLASS_NAME, "container") if element is not None: element_list = element.find_elements( By.XPATH, "//div[contains(@class, 'feed-card')]/div[contains(@class, 'bili-feed-card')]/div[contains(@class,'bili-video-card')]//h3/a" ) for title in element_list: print(title.text) sleep(8) except Exception as e: print(f'Something went wrong: {e}') finally: print('The try except is finished') if driver is not None: driver.quit()
你参数名用错了
你要看你用的selenium版本。我这个是老版本的语法,切换selenium可以适配
回复 小布_老师:是的,我用的最新的版本
可以降低版本,或者按提示,修改新版本的代码,可以锻炼一下查文档和更新代码。
如果你用的selenium比较新,则chrome_options要改成optionswebdriver.Chrome(options=chrome_options)
登录后可查看更多问答,登录/注册
4阶段带你完成从Python爬虫小白,到能力者的蜕变
220 6
80 5
143 5
350 4
348 4
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号