所以我试图获取一个音云音轨ID,我不确定该怎么做,但到目前为止,我已经确定我应该能够从音云的歌曲页面中读取一个meta标签。 。这是我的代码:
string url = "https://soundcloud.com/hardstyle/scarphase-angernoizer-chaos-of-the-mayans-feat-tha-watcher-bkjn-vs-partyraiser-2017-anthem";
HtmlWeb w = new HtmlWeb();
HtmlDocument d = w.Load(url);
var x = d.DocumentNode.SelectSingleNode("/html/head/meta[30]");
Console.WriteLine(x.InnerText);
我正在尝试阅读以下标签:
<meta property="twitter:app:url:googleplay" content="soundcloud://sounds:322162984">
所以我可以获取内容,然后获取曲目ID
当试图显示变量X的内部文本时,什么也没显示,设置断点时说X为空,有人可以解释我为什么这样做以及如何解决它吗?
答案 0 :(得分:0)
您需要获取属性,该标记没有内部文本。
改为使用var x = d.DocumentNode.SelectSingleNode("/html/head/meta[30]@content").Value;
。这会将您的查询指向内容标签,您可以在其中提取soundcloud://...
。
答案 1 :(得分:0)
您需要读取所选节点的属性“ content”:
string url = "https://soundcloud.com/hardstyle/scarphase-angernoizer-chaos-of-the-mayans-feat-tha-watcher-bkjn-vs-partyraiser-2017-anthem";
HtmlWeb w = new HtmlWeb();
HtmlDocument d = w.Load(url);
var x = d.DocumentNode.SelectSingleNode("/html/head/meta[30]").Attributes["content"].Value;
Console.WriteLine(x);
答案 2 :(得分:0)
// Get the property attribute of x
var prop = x.GetAttributeValue("property", "");
Console.WriteLine(prop );
// output: twitter:app:url:googleplay
//similarly get the content attribute of x
var content = x.GetAttributeValue("content", "");
Console.WriteLine(content );
//output : soundcloud://sounds:322162984
希望这会有所帮助。