我很抱歉,因为我仍然在学习LINQ和HtmlAgilityPack的进程访问值(),但我想指定标题和链接已经创建的字符串值。换句话说,我如何访问这个.ToList()的值?如何到LINQ .ToList内使用HtmlAgilityPack
下面是我的代码:
string imgTitle;
string imgLink;
private void getCaption(string txt)
{
HtmlDocument htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml("<html><head></head><body>" + txt + "</body></html>");
if (htmlDoc != null)
{
var elements = htmlDoc.DocumentNode.SelectNodes(@"//img[@src]").Select(img => new
{
Link = img.Attributes["src"].Value,
Title = img.Attributes["alt"].Value
}).ToList();
}
imgTitle = elements[0]["Title"]; //I thought i could do this
对不起,一个愚蠢的问题,但我还没有看到任何好解释了那里到LINQ工作原理和ToList功能。当我打印的元素[0]我得到这样的两个值,请{link = www.link.url,标题=有些标题}
谢谢我爱你! – Ammar