在使用 Selenium 进行网页内容抓取时,常常会遇到一些棘手的问题,如ElementNotInteractableException或StaleElementReferenceException。这些问题在抓取像 Binance 新上币公告这样的动态网页时尤为常见。本文将结合实例,详细介绍如何解决这些问题。
背景介绍
假设我们要抓取 Binance 新上币公告中的链接内容,用户的代码遇到了如下问题:
# 用户原代码div_elements=driver.find_elements(By.CSS_SELECTOR,'.css-148156o .css-1tl1y3y')fordiv_elementindiv_el