【发布时间】:2021-07-23 02:53:33
【问题描述】:
我的代码运行良好并打印所有行的标题但带有下拉菜单的行。
例如,如果单击,第 4 行会有一个下拉菜单。我实现了一个 try,理论上它会启动下拉菜单,然后拉出标题。
但是我对带有这些下拉菜单的行的点击/抓取没有打印。
预期输出 - 打印所有标题,包括下拉列表中的标题。
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')
productlist=soup.find_all('div',class_='card item-container session')
for property in productlist:
sessiontitle=property.find('h4',class_='session-title card-title').text
print(sessiontitle)
try:
ifDropdown=driver.find_elements_by_class_name('item-expand-action expand')
ifDropdown.click()
time.sleep(4)
newTitle=driver.find_element_by_class_name('card-title').text
print(newTitle)
except:
newTitle='none'
【问题讨论】:
-
item-expand-action expand 应该是 item-expand-action.expand
-
你的发现,一旦按照之前的评论进行调整,就会返回一个包含 8 个要打开的项目的列表
标签: python selenium web-scraping beautifulsoup