【发布时间】:2021-03-18 02:31:13
【问题描述】:
我的代码应该进入一个网站,浏览 2 个页面,然后打印出每一行中的所有标题和 URL/href。
目前 - 我的代码可以很好地进入这 2 个页面,但是 它只打印出每个页面的第一个标题,而不是每行的每个标题。
该页面确实有一些 JavaScript,我想这可能就是为什么它没有在每一行中显示任何链接/urls/hrefs 的原因?理想的 id 喜欢打印每一行的 URL。
from selenium import webdriver
import time
driver = webdriver.Chrome()
for x in range (1,3):
driver.get(f'https://www.abstractsonline.com/pp8/#!/9325/presentations/endometrial/{x}')
time.sleep(3)
page_source = driver.page_source
eachrow=driver.find_elements_by_xpath("//li[@class='result clearfix']")
for item in eachrow:
title=driver.find_element_by_xpath("//span[@class='bodyTitle']").text
print(title)
【问题讨论】:
-
我不知道这是否有帮助,但请检查 realpython 上的 Beautiful Soup Web Scraper -> link
-
BeautifulSoup 似乎无法解析此页面
标签: python selenium web-scraping beautifulsoup