需要解析网站播放的音乐并从播放列表中获取歌曲数据
具有此表(RU版本):
<tr class="song-row " data-id="ef713e30-ea6c-377d-a1a6-bc55ef61169c" data-song-type="7" data-subscription-links="true" data-index="0"><td data-col="index"><span class="column-content">1<button aria-label="Воспроизвести: HUMBLE." data-id="play" class="aria-play-button"></button></span></td><td data-col="title"><div class="title-right-items"><iron-icon icon="av:explicit" role="img" aria-label="Не предназначено для детей" title="Не предназначено для детей" class="x-scope iron-icon-0"><svg viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" class="style-scope iron-icon" style="pointer-events: none; display: block; width: 100%; height: 100%;"><g class="style-scope iron-icon"><path d="M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-4 6h-4v2h4v2h-4v2h4v2H9V7h6v2z" class="style-scope iron-icon"></path></g></svg>
例如,这里-歌曲的名称
<span class="column-content tooltip"><img src="https://lh3.googleusercontent.com/UVqWaml2fkVCgsErJIZBLeSn6LlOCI1t_W68-1HABS8dos9fWNn-4cGkboaKf-5Ro_YhthMx=s60-e100-c" alt="">HUMBLE.</span>
如何获取数据,例如歌曲名称,艺术家等?
答案 0 :(得分:0)
AngleSharp自述文件有一个非常相似的示例(请参见https://github.com/AngleSharp/AngleSharp.Samples/blob/master/AngleSharp.Samples.Demos/Snippets/BigBang.cs):
// Setup the configuration to support document loading
var config = Configuration.Default.WithDefaultLoader();
// Load the names of all The Big Bang Theory episodes from Wikipedia
var address = "http://en.wikipedia.org/wiki/List_of_The_Big_Bang_Theory_episodes";
// Asynchronously get the document
var document = await BrowsingContext.New(config).OpenAsync(address);
// This CSS selector gets the desired content
var cellSelector = "tr.vevent td:nth-child(3)";
// Perform the query to get all cells with the content
var cells = document.QuerySelectorAll(cellSelector);
// We are only interested in the text - select it with LINQ
var titles = cells.Select(m => m.TextContent);
由于您没有发布配置/与AngleSharp相关的方法,因此我认为您肯定它们可以正常工作。因此,为简单起见,我将省略它们。
现在,根据您的情况,它可能会转换为:
var rows = document.QuerySelectorAll("tr.song-row");
var songInfos = rows.Select(row => new {
Title = row.QuerySelector(".column-content.tooltip")?.TextContent,
});
注意:您带来的歌曲标题示例确实非常通用;我没有看到与歌曲标题相关的任何内容。因此,我假设您需要从给定的行中选择特定的列(例如,第5列)。在上面的示例中,我只是将选择器用于显示的元素。
HTH!