Retrieve <ul> and <li> tags which in div in div.

Topics: Developer Forum, User Forum
Jan 29, 2015 at 2:38 PM
Edited Jan 29, 2015 at 2:39 PM
Hello
Here is my HTML
<div class="main">
<div class="front>
<div class="end">
<ul class="1">
<li>
<a href="www.example.com/1asp" title="abc">
</li>
<li class="2">
<a href="www.example.com/2asp" title="def">
</li>
<li class="3">
<a href="www.example.com/3asp" title="ghj">
</li>
</ul>
</div>
</div>
</div>
Ho can I reach urls which in hrefs and titles with HAP?
Thanks in advance.
Mar 2, 2015 at 8:05 AM
I'd like to know this as well ! :)
Mar 2, 2015 at 9:10 AM
Edited Mar 2, 2015 at 9:17 AM
    var lnks = document.DocumentNode.SelectNodes("//ul[@class='linkNewsList']//li//a");
                               //.Where(node => !nodesToExclude1.Contains(node) && node.Attributes["target"].Value.Contains("_blank"))

        if (lnks != null)
        {
            foreach (HtmlNode node in lnks)
            {
                DataRow dtRow = HurriyetDataTable.NewRow();
                dtRow["Url"] = node.Attributes["href"].Value;
                var Title = node.Attributes["title"].Value;
                dtRow["Title"] = node.Attributes["title"].Value;
                dtRow["SourceID"] = "0";
                SqlDataSourceHitCount.SelectParameters["Url"].DefaultValue = node.Attributes["href"].Value;
                DataView dvHit = (DataView)SqlDataSourceHitCount.Select(DataSourceSelectArguments.Empty);

                SqlDataSourceHitCount.SelectParameters["Url"].DefaultValue = node.Attributes["href"].Value;
                DataView dvHitOneHoureBefore = (DataView)SqlDataSourceHitCount.Select(DataSourceSelectArguments.Empty);

                if (dvHit.Table.Rows[0][0] != System.DBNull.Value)
                {
                    int HitCount = (int)dvHit.Table.Rows[0][0];
                    dtRow["HitCount"] = HitCount;
                }
                if (Title.Length > 40)
                {
                    Title = Title.Substring(0, 40) + "...";
                    dtRow["Text"] = Title;
                }
                else
                {
                    dtRow["Text"] = Title;
                }
                HurriyetDataTable.Rows.Add(dtRow);
            }
        }
        ListViewHurriyet.DataSource = HurriyetDataTable;
        ListViewHurriyet.DataBind();
    }
//also you can copy xpath and use it.