【问题标题】:how can i scrape the all courses from the website我如何从网站上抓取所有课程
【发布时间】:2020-07-01 08:04:33
【问题描述】:

我想抓取此页面 [此页面][1] 上的所有课程名称,这是我的代码

URL = 'https://www.bachelorsportal.com/search/bachelors-degrees/computer-science-it/#q=di-24|lv-bachelor?'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')

results = soup.findAll(class_='StudyTitle')
print(results)

我得到一个空数组

【问题讨论】:

  • 搜索结果内容可能是用JS动态渲染的,所以没有给定id的标签
  • 如何取消课程?

标签: python web-scraping beautifulsoup request


【解决方案1】:

@baduker 是对的,课程内容是通过 JS 动态加载的。查看 URL 的主请求empty response

显而易见的解决方案是使用 selenium 的浏览器自动化(例如无头 Chrome)。

破解

您可能会发现 XHR/Ajax 请求返回课程内容(以 json 格式)和 perform them by Python 以获取内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2018-06-09
    • 2021-02-15
    • 2013-03-31
    • 1970-01-01
    • 2022-10-14
    相关资源
    最近更新 更多