Selenium/Webscrape this field

我的代碼運行良好,打印所有行的標題,但帶有下拉列表的行除外。

例如,如果單擊,第4行有一個下拉列表。我實現了一個嘗試,在理論上會啟動下拉列表,然后拉標題。

但是當我執行click()并嘗試打印時,對于帶有這些下拉列表的行,它們不會打印。

應為output-打印所有標題,包括下拉列表中的標題。

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'
? 最佳回答:
import requests
from bs4 import BeautifulSoup
import pandas as pd


def get_soup(content):
    return BeautifulSoup(content, 'lxml')


def my_filter(req, content):
    try:
        r = req.get(content['href'])
        soup = get_soup(r.text)
        return [x.text for x in soup.select('.card-title')[1:]]
    except TypeError:
        return 'N/A'


def main(url):
    with requests.Session() as req:
        for page in range(1, 2):
            print(f"Extracting Page# {page}\n")
            params = {
                "p": page
            }
            r = req.get(url, params=params)
            soup = get_soup(r.text)
            goal = {x.select_one('.session-title').text: my_filter(
                req, x.select_one('.item-expand-action')) for x in soup.select('.card')}
        df = pd.DataFrame(goal.items(), columns=['Title', 'Menu'])
        print(df)


main('https://cslide.ctimeetingtech.com/esmo2021/attendee/confcal/session/list')

Output:

                                                Title                                               Menu
0                      Educational sessions on-demand                                                N/A
1                          Special Symposia on-demand                                                N/A
2                Multidisciplinary sessions on-demand                                                N/A
3   Illumina - Diagnosing Non-Small Cell Lung Canc...  [Illumina gives an update on their IVD road ma...
4   MSD - Homologous Recombination Deficiency: BRC...  [Welcome and Introductions, Homologous Recombi...
5   Servier - The clinical value of IDH inhibition...  [Isocitric dehydrogenase: an actionable geneti...
6   AstraZeneca - Redefining Breast Cancer – Biolo...  [Welcome and Opening, Redefining Breast Cancer...
7   ITM Isotopen Technologien München AG - A Globa...  [Welcome & Introduction, Changes in the Incide...
8   MSD - The Role of Biomarkers in Patient Manage...  [Welcome and Introductions, The Role of Pd-L1 ...
9   AstraZeneca - Re-evaluating the role of gBRCA ...  [Welcome and introduction, What do we know abo...
10  Novartis - Unmet needs in oncogene-driven NSCL...  [Welcome and introduction, Unmet needs in onco...
11                                    Opening session                                                N/A
主站蜘蛛池模板: 亚洲一区二区三区免费观看| 亚洲AV成人精品日韩一区18p| 国产一区二区三区精品视频 | 无码国产精成人午夜视频一区二区| 中文字幕无线码一区二区 | 亚洲AV本道一区二区三区四区| 亚洲综合在线一区二区三区| 国产丝袜美女一区二区三区| 乱人伦一区二区三区| 国产精品第一区揄拍无码| 亚洲一区电影在线观看| 国产精品视频一区二区三区无码| 亚洲一区二区三区免费| 男人的天堂精品国产一区| 精品国产一区二区二三区在线观看 | 老湿机一区午夜精品免费福利| 国产精品合集一区二区三区| 亚洲一区爱区精品无码| 日本高清成本人视频一区| 亚洲日本一区二区三区在线不卡 | 国产一区二区三区播放| 无码视频一区二区三区| 国产精品一区二区久久精品| 色婷婷综合久久久久中文一区二区 | 无码人妻一区二区三区兔费| 亚洲AV成人一区二区三区在线看 | 手机福利视频一区二区| 极品少妇一区二区三区四区| 亚洲综合一区二区三区四区五区| 毛片一区二区三区| 久久精品国内一区二区三区| 在线观看一区二区精品视频| 日本一区二区三区日本免费| 日亚毛片免费乱码不卡一区| 精品国产一区二区三区久久蜜臀| 综合久久一区二区三区 | 人妻无码一区二区三区| 久久精品国产一区二区| 国产精品丝袜一区二区三区| 精品无码av一区二区三区| 国产成人久久精品区一区二区|