簡體   English   中英

從硒下拉列表中獲取所有組合,不帶選項或選擇標簽

[英]Get all combinations from selenium drop down list without options or select tag

我正在使用Selenium的相應網站: http : //calstate-la.bncollege.com/webapp/wcs/stores/servlet/TBWizardView ?catalogId=10001&langId=-1&storeId= 30556

我在此網站上的目標是從各自的下拉菜單中獲得部門,課程和科目的所有可能組合。 我遇到的主要問題是我想不出任何方法從下拉菜單中獲取值。

根據與我類似的其他堆棧溢出問題,他們提到了使用選擇標簽和選項標簽的解決方案。 但是,當我查看此頁面源代碼時,下拉菜單沒有此類標簽。

因此,在嘗試從下拉菜單中獲取所有組合時,我需要幫助,但是在特殊情況下,我不知道如何進行操作。 我還想提到我在使用Python。

我實際上已經嘗試過在這里使用selenium ,但是由於頁面的異步性質和“人工”下拉菜單( 這是我到目前為止的內容 ),它確實變得非常痛苦。

這是使用requestsBeautifulSoup的另一種方法(根本不需要瀏覽器)。

這個想法是模擬填充下拉列表的垃圾請求:

from bs4 import BeautifulSoup
import requests

CATALOG = 10001
STORE = 30556

url = 'http://calstate-la.bncollege.com/webapp/wcs/stores/servlet/TBWizardView?catalogId={catalog}&langId=-1&storeId={store}'.format(catalog=CATALOG,
                                                                                                                                     store=STORE)
xhr_url = 'http://calstate-la.bncollege.com/webapp/wcs/stores/servlet/TextBookProcessDropdownsCmd'
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36'}

session = requests.Session()
response = session.get(url, headers=headers)
soup = BeautifulSoup(response.content)

campus = soup.find('input', attrs={'name': 'campus1'}).get('value')
book_row = soup.find('div', class_='bookRowContainer')

params = {
    'campusId': campus,
    'deptId': '',
    'courseId': '',
    'sectionId': '',
    'storeId': STORE,
    'catalogId': CATALOG,
    'langId': '-1',
    'dropdown': 'term'
}

terms = book_row.select('li.termOption')
for term in terms:
    params['termId'] = term.get('data-optionvalue')
    response = session.post(xhr_url, params=params, headers=headers)
    print response.content

這將以JSON格式打印所有術語的所有部門。

2014年秋季:

[
    {"categoryName":"AAAS","categoryId":"63420700","categoryIdentifier":"670_1_F14_4","title":"AAAS"},
    {"categoryName":"ACCT","categoryId":"63420752","categoryIdentifier":"670_1_F14_5","title":"ACCT"},
    ...
]

2014年夏季:

[
    {"categoryName":"AAAS","categoryId":"63007512","categoryIdentifier":"670_1_A14_4","title":"AAAS"},
    {"categoryName":"ACCT","categoryId":"63007490","categoryIdentifier":"670_1_A14_5","title":"ACCT"},
    ...
]

讓你CourseSection一部分作為家庭作業。

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM