无法使用发布请求获取某些项目

时间:2018-09-17 12:53:59

标签: python python-3.x post web-scraping beautifulsoup

我已经用python编写了一个脚本,以从网站获取课程资料列表。要显示课程材料,有必要填写一些inputs,如果您从其登录页面跟踪Find Textbooks链接(如在图一中看到的那样),则可以找到它们。

但是,当您相应地填写输入内容时,将显示课程材料(在图2中可以看到我的操作方式)。

似乎,我以正确的方式完成了所有操作,但无法获取项目。当我执行脚本时,它不会解析任何内容,也不会引发任何错误。我在脚本中使用的选择器应该是准确的。

Link to the landing page

这是我到目前为止的尝试:

import requests
from bs4 import BeautifulSoup

url = "https://uncg.bncollege.com/webapp/wcs/stores/servlet/BNCBTBListView"

payload = {
    'storeId':'19069',
    'catalogId':'10001',
    'langId':'-1',
    'clearAll':'', 
    'viewName':'TBWizardView',
    'secCatList':'', 
    'removeSectionId':'', 
    'mcEnabled':'N',
    'showCampus':False,
    'selectTerm':'Select Term',
    'selectDepartment':'Select Department',
    'selectSection':'Select Section',
    'selectCourse':'Select Course',
    'campus1':'17548065',
    'firstTermName_17548065':'Fall 2018',
    'firstTermId_17548065':'84599238',
    'section_1': '85441456',
    'section_2':'', 
    'section_3':'',
    'section_4':'', 
    'numberOfCourseAlready':'4'
}

with requests.Session() as s:
    s.headers={"User-Agent":"Mozilla/5.0"}
    res = s.post(url,data=payload)
    soup = BeautifulSoup(res.text,"lxml")
    for items in soup.select("#skipNavigationToThisElement a"):
        print(items.text)

任何解决此问题的帮助将不胜感激。

图片一 enter image description here

图片二

enter image description here

1 个答案:

答案 0 :(得分:0)

使用硒来获取动态网站,然后获取该网站的响应文本。

相关问题