Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python BS4 find_all与Genius歌词中的mini_卡片标题类不匹配_Python_Html_Web Scraping_Beautifulsoup - Fatal编程技术网

Python BS4 find_all与Genius歌词中的mini_卡片标题类不匹配

Python BS4 find_all与Genius歌词中的mini_卡片标题类不匹配,python,html,web-scraping,beautifulsoup,Python,Html,Web Scraping,Beautifulsoup,我正在尝试从genius歌词的歌曲搜索中获取歌曲标题,但是,使用.find_all(“div”,class=“mini_card-title”)尝试获取歌曲名称不起作用,但是.find_all(“div”class=“header”)起作用 这只是我正在从事的一个小项目,它运行在VisualStudio2019上,使用python 3.7。我使用两个模块:请求和bs4。我曾尝试更改解析器,将find_all更改为find和select,但这些都没有帮助 不起作用的代码: soup = bs4.B

我正在尝试从genius歌词的歌曲搜索中获取歌曲标题,但是,使用.find_all(“div”,class=“mini_card-title”)尝试获取歌曲名称不起作用,但是.find_all(“div”class=“header”)起作用

这只是我正在从事的一个小项目,它运行在VisualStudio2019上,使用python 3.7。我使用两个模块:请求和bs4。我曾尝试更改解析器,将find_all更改为find和select,但这些都没有帮助

不起作用的代码:

soup = bs4.BeautifulSoup(res.text, "html.parser")
a = soup.find_all("div", class_="mini_card-title")
print(a)
有效的代码:

soup = bs4.BeautifulSoup(res.text, "html.parser")
a = soup.find_all("div", class_="header")
print(a)

我希望获得歌曲的名称,即使获得页面上所有歌曲的名称也可以,但是目前我只获得一个空白列表。

您可以使用页面用于动态获取结果的API获取所有信息。我展示了打印一些标题,但探索json响应,看看您想要什么

import requests
from bs4 import BeautifulSoup as bs

r = requests.get('https://genius.com/api/search/multi?per_page=5&q=something').json()
for item in r['response']['sections']:
    for subitem in item['hits']:
        if 'title' in subitem['result']:
            print(subitem['result']['title'])

例如在哪一页?当这两种方法中的一种起作用时,有什么问题吗?如果有,请提供urlpossible@Qharr,我使用URL:的方式如下:res=requests.get(“)在标题中使用短语“Not working”或“Not work”是获得非常负面的响应的好方法,而不是狭义地描述特定的、定义良好的行为(”按类过滤时未返回任何响应”,f/e)。非常感谢!这完美地解决了我的问题。但有一个问题:您是如何进入该api页面的?()?我如何进入不同网站上的类似api页面?我使用了“网络”选项卡(F12)检查web流量并刷新网页。然后,我使用了页面外的值并搜索记录的web流量。请参见此处: