我很抱歉,因爲我仍然在學習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