繁体   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