【发布时间】:2021-09-29 05:45:23
【问题描述】:
我的代码运行良好并打印所有行的标题,但带有下拉菜单的行。
例如,如果单击,第 4 行会有一个下拉菜单。我实现了一个“尝试”,理论上它会单击下拉菜单,然后拉出标题。
但是当我执行 click() 并尝试打印时,对于带有这些下拉菜单的行,它们没有打印。
预期输出 - 打印所有标题,包括下拉列表中的标题。
用户在此链接StackOverFlowAnswer 上提交了答案,但他的答案格式不同,我不知道如何添加日期、时间、椅子等字段或顶部的字段用他的方法说“按需”
任何方法都将不胜感激,希望将其放入数据框中。谢谢
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.action_chains import ActionChains
import time
driver = webdriver.Chrome()
actions = ActionChains(driver)
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:
actions.move_to_element_with_offset(property,0,0).perform()
time.sleep(4.5)
sessiontitle=property.find_element_by_xpath(".//h4[@class='session-title card-title']").text
#print(sessiontitle)
ifDropdown=property.find_elements_by_xpath(".//*[@class='item-expand-action expand']")
if(ifDropdown):
ifDropdown[0].click()
time.sleep(4)
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)
new_titles.add(title)
【问题讨论】:
-
这能回答你的问题吗? Selenium/Webscrape this field
-
同一 OP 的另一个欺骗 stackoverflow.com/questions/68472330/…
-
他们不是骗子..这篇文章中引用的字段未包含在原文中
标签: selenium web-scraping beautifulsoup request