我想从此页面中提取标题和其他信息,请帮忙。
我这样做是为了从这个网址获取mp3的下载链接:http://mp3monkey.net/mp3/Eminem.html
private HtmlNodeCollection GetSongNodesMp3Monkey(string pageUri)
{
HtmlDocument document = web.Load(pageUri);
HtmlNode documentNode = document.DocumentNode;
return documentNode.SelectNodes("//a[@href]");
}
void Mp3Monkey(HtmlNodeCollection songs)
{
foreach (HtmlNode s in songs)
{
HtmlAttribute aa = s.Attributes["href"];
if (aa.Value.EndsWith("?dl=1"))
{
list.Items.Add(aa.Value.Replace("?dl=1",""));
}
}
}
但我想提取其他信息,如标题和持续时间以及艺术家,请帮我这样做。
示例Html:
<td>
<div class="dd" style="width:34px; cursor:pointer; padding-top: 2px; padding bottom: 4px;" onclick="gopl(this)" id="plid_18ffbe2d9efe71aed310552f4f79ad55">
<span class="ui-icon ui-icon-play" id="ui-icon-play">
<img src="Eminem%20Mp3%20Download_files/play.png" title="Play">
</span>
<span class="ui-icon ui-icon-pause" id="ui-icon-pause" style="display:none">
<img src="Eminem%20Mp3%20Download_files/pause.png" title="Pause">
</span>
<!--<span style="display:none;" id="norber">http://mp3monkey.net/audio/92960819/17163345/play.mp3</span>-->
<span style="display:none;" id="norber">http://mp3monkey.net/audio/17163345/92960819/Eminem_-_Love_the_Way_You_Lie_feat_Rihanna_.mp3</span>
<span style="display:none;" id="xftitle">Eminem - Love the Way You Lie (feat. Rihanna)</span>
</div>
</td>
<td style="width:34px">
<div class="dd" style="width:34px; padding-top: 2px; padding-bottom: 4px;">
<noindex>
<div id="addmp3_18ffbe2d9efe71aed310552f4f79ad55">
<img src="Eminem%20Mp3%20Download_files/add.png" id="is_add1" title="Add to Playlist" style="cursor:pointer;" \="" border="0">
<img src="Eminem%20Mp3%20Download_files/addok.png" title="Added" id="is_add2" style="display:none">
<span style="display:none" id="aid">92960819</span>
<span style="display:none" id="oid">17163345</span>
<span style="display:none" id="autor">Eminem</span>
<span style="display:none" id="title">Love the Way You Lie (feat. Rihanna)</span>
<span style="display:none" id="time">263</span>
</div>
</noindex>
</div>
</td>
答案 0 :(得分:1)
var xpath = "//div[@class='dd']/noindex/div";
var songs = from song in hdoc.DocumentNode.SelectNodes(xpath)
select new {
Author = song.SelectSingleNode("span[@id='autor']").InnerText,
Title = song.SelectSingleNode("span[@id='title']").InnerText,
Time = song.SelectSingleNode("span[@id='time']").InnerText
};
输出:
[
{
Author: "Eminem",
Title: "Love the Way You Lie (feat. Rihanna)",
Time: "263"
},
{
Author: "Eminem ft. Akon ",
Title: "Smack That ",
Time: "217"
},
{
Author: "Dr. Dre Feat. Eminem & Skylar Grey",
Title: "I Need A Doctor ( 2011 )",
Time: "283"
},
...
]