c# - Parse html table using LINQ and HtmlAgilityPack -
i want parse date, link text , link href table class='nice' on web page http://cslh.cz/delegace.html?id_season=2013
i have created object delegationlink
public class delegationlink { public string date { get; set; } public string link { get; set; } public string anchor { get; set; } }
and used linq create list of delegationlink
var parsedvalues = table in htmldoc.documentnode.selectnodes("//table[@class='nice']") date in table.selectnodes("tr//td") link in table.selectnodes("tr//td//a") .where(x => x.attributes.contains("href")) select new delegationlink { date = date.innertext, link = link.attributes["href"].value, anchortext = link.innertext, }; return parsedvalues.tolist();
which takes date column ony 1 , combine link column in every row, want take every row in table , date, href , hreftext row. new linq , used google 4 hours without effect. help.
well, that's rather easy, have select tr
's in selectnodes
function calls , adjust code bit. this.
var parsedvalues = htmldoc.documentnode.selectnodes("//table[@class='nice']/tr").skip(1) .select(r => { var linknode = r.selectsinglenode(".//a"); return new delegationlink() { date = r.selectsinglenode(".//td").innertext, link = linknode.getattributevalue("href",""), anchor = linknode.innertext, }; } ); return parsedvalues.tolist();
Comments
Post a Comment