【发布时间】:2021-10-23 11:01:29
【问题描述】:
我正在尝试创建一个脚本来从 Udemy 课程中抓取价格数据。 我正在努力导航 HTML 树,因为我要查找的元素位于多个嵌套 div 中。
我尝试了什么:
response = requests.get(url)
print(response)
doc = BeautifulSoup(response.text, "html.parser")
parent_div = doc.find(class_="sidebar-container--purchase-section--17KRp")
print(parent_div.find_all("span"))
甚至:
response = requests.get(url)
print(response)
doc = BeautifulSoup(response.text, "html.parser")
main = doc.find(class_="generic-purchase-section--main-cta-container--3xxeM")
title = main.select_one("div span span span")
这是网址:https://www.udemy.com/course/the-complete-web-development-bootcamp/
尝试搜索 HTML 中的所有跨度,但我正在搜索的特定跨度没有出现,可能是因为它嵌套在 div 中?
不胜感激!
【问题讨论】:
-
您愿意分享实际网址吗?
-
刚刚添加了关于错过那部分的抱歉
标签: python html web-scraping beautifulsoup