无法加载页面来刮取文章标签

问题描述 投票:0回答:1

我试图在这个链接上抓取文章的内容:https://onlinelibrary.wiley.com/doi/full/10.1111/jvim.15224

我使用Selenium加载页面(PhantomJS和Firefox),但我似乎无法获得文章标签。

这行是等待页面加载:

element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "article-section__sub-title section1")))

或者,我也试图等待文章标签加载。

但是,驱动程序会在几秒后继续运行,但每当我检查等待后得到的html时,唯一出现的是“头部”和“正文”标签 - 只是标签,没有内容。

知道我在页面加载和刮取文章标签时做错了什么吗?

python selenium selenium-webdriver screen-scraping article
1个回答
1
投票

要刮除文章标签而不是使用presence_of_element_located(),您需要使用visibility_of_all_elements_located()方法,您可以使用以下解决方案:

  • 代码块: driver.get("https://onlinelibrary.wiley.com/doi/full/10.1111/jvim.15224") tags = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, "h3.article-section__sub-title.section1"))) for tag in tags: print(tag.text)
  • 控制台输出: Background Objective Animals Methods Results Conclusions and Clinical Importance
© www.soinside.com 2019 - 2024. All rights reserved.