Reputation: 13
var web = new HtmlWeb();
var doc = web.Load(page);
var Articles = doc.DocumentNode.SelectNodes("//*[@class = 'b-product-grid-tile js-tile-container']");
var href = doc.DocumentNode.SelectNodes("//a[@href]");
foreach (HtmlNode link in href)
{
HtmlAttribute att = link.Attributes["href"];
_entries.Add(new EntryModel { Link = att });
// att.ToString(); <----- Want to convert the HtmlAttribute to a string.
}
Full Code of my Scraper:
EntryModel List:
Main Window:
The links I need:
Upvotes: 1
Views: 63
Reputation: 190
The easiest would be using the System.Web.Mvc.TagBuilder
class:
var attributes = new { @class = "myClass", id = "elId" };
var tag = new TagBuilder("href");
tag.MergeAttributes(new RouteValueDictionary(attributes));
return tag.ToString();
Upvotes: 1