Frage

I want to extract title and other information from this page please help.

I have done this to get the download links of the mp3s from this url: 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",""));
        }
     }
}

But I want to extract other information also such as title and duration and artist, please help me to do this.

Sample 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>
War es hilfreich?

Lösung

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
            };

Output:

[
  {
    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 &amp; Skylar Grey",
    Title: "I Need A Doctor ( 2011 )",
    Time: "283"
  },
  ...
]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top