【发布时间】:2021-09-29 09:20:21
【问题描述】:
作为问题重新发布似乎仍然很突出 -
一个网站有几行标题。其中一些标题(标题为蓝色)在单击时展开并显示更多标题。附上一个例子。
我的目标是执行一次抓取并提取所有标题、日期和时间。此外,如果可能,所有的标题(第 1 行的示例是它显示“按需”的位置)
当前代码- 存在一致性问题,无法收集所有下拉字段。
from selenium import webdriver
from bs4 import BeautifulSoup
import time
driver = webdriver.Chrome()
driver.get('https://cslide.ctimeetingtech.com/esmo2021/attendee/confcal/session/list')
time.sleep(4)
page_source = driver.page_source
soup = BeautifulSoup(page_source,'html.parser')
new_titles = set()
productlist=driver.find_elements_by_xpath("//div[@class='card item-container session']")
for property in productlist:
sessiontitle=property.find_element_by_xpath(".//h4[@class='session-title card-title']").text
print(sessiontitle)
ifDropdown=driver.find_elements_by_xpath(".//*[@class='item-expand-action expand']")
if(ifDropdown):
ifDropdown[0].click()
time.sleep(8)
open_titles = driver.find_elements_by_class_name('card-title')
for open_title in open_titles:
title = open_title.text
if(title not in new_titles):
print(title)
time.sleep(4)
new_titles.add(title)
【问题讨论】:
-
这能回答你的问题吗? Selenium/Webscrape this field
-
它没有,它没有提取所有的日期和时间,如果可能的话,所有的标题(第 1 行的一个例子是它说“按需”)我不知道如何你做了你自己的部分代码来添加这个 - 在帖子中提到
标签: selenium web-scraping beautifulsoup request css-selectors