【发布时间】:2018-05-22 11:43:45
【问题描述】:
所以我试图访问颜色部分中的title 属性。
因此,如果您将鼠标悬停在产品右侧的任何小图像上,您会看到上面写着Color 名称。
我已经设法导航到那里,但我一生都无法弄清楚如何获得title 属性。目前它正在打印节点,但我想访问 title 属性。
如何正确访问title属性并打印出图片对应的颜色?
This is the test link I am using (AliExpress)
Console.WriteLine("Product URL: ");
//Declare the URL
string url = Console.ReadLine();
// HtmlWeb - A Utility class to get HTML document from http
var web = new HtmlWeb();
//Load() Method download the specified HTML document from an Internet resource.
var doc = web.Load(url);
var nodes = doc.DocumentNode.SelectNodes("//li[@class = 'item-sku-image']");
foreach (var node in nodes)
{
//var colors = node.Attributes["/a[title]"].Value;
Console.WriteLine(node);
}
Console.ReadLine();
【问题讨论】:
标签: c# .net xpath nodes html-agility-pack