python - 尝试用beautifulsoup 抓取soundcloud
问题描述
我正在尝试抓取 soundcloud和其他音乐平台的数据,但我似乎被困在 soundcloud,因为我得到 None、AttributeError 或 [],但是当我尝试抓取常规网站(非音乐)时。我得到数据。我在做什么错请帮忙。
from bs4 import BeautifulSoup
import requests
html_text = requests.get('https://soundcloud.com/jujubucks').text
soup = BeautifulSoup(html_text,'lxml')
song = soup.find('li', class_='soundList__item')
print(song)
此代码返回此。
None or AttributeError.
解决方案
查看原始输出(代码中的变量汤)。
此代码提取原始歌曲标题:
from bs4 import BeautifulSoup
import requests
html_text = requests.get('https://soundcloud.com/jujubucks').text
soup = BeautifulSoup(html_text, 'lxml')
song = soup.find_all('h2', itemprop='name')
print(song)
上面代码的输出列表中的项目示例:
<h2 itemprop="name"><a href="/jujubucks/squad-too-deep-ft-cool-prince" itemprop="url">Squad Too Deep Ft. Cool Prince (Outro)</a>
但如果没有 selenium 或 scrapy,您无法从该网站上抓取所有数据,它们使用动态加载的内容。
推荐阅读
- javascript - 节点中的垃圾收集
- android - MotionLayout KeyCycle 和 KeyTimeCycle
- python - Deleting elements of lists, within other lists in Python
- slf4j - 以编程方式打开或关闭到 Slf4j 的全局 RestAssured 日志记录
- python - Tksheet宽度参数不改变宽度?
- r - 如何在plotly中使用layout()函数来设置轴标题R
- smalltalk - whileTrue 在闭包 Smalltalk 中?
- reactjs - onClick 第二次没有路由到正确的页面
- docker - Canonical LXD 容器软件和 docker 容器软件之间的主要区别是什么?
- java - java模块化和cxf-xjc-plugin从xsd文件生成包