C# 查询使用HTML Agility Pack解析的网页时出现问题
我有以下源代码snipet:C# 查询使用HTML Agility Pack解析的网页时出现问题,c#,web-scraping,html-agility-pack,C#,Web Scraping,Html Agility Pack,我有以下源代码snipet: <div class = "discount_tools_row"> <div class = "discount_tools"> <ul> <li><a href = "#" class = "share-discount" rel = "nofollow"></a></li> <li><a href = "/deal/map
<div class = "discount_tools_row">
<div class = "discount_tools">
<ul>
<li><a href = "#" class = "share-discount" rel = "nofollow"></a></li>
<li><a href = "/deal/map/4243683"
class = "show-location"
title = "הראה מקום על מפה"
data-address = "רח' האצ"ל 39, ראשון לציון"></a></li>
</ul>
<link rel = "prerender"
href = "http:/ / www.bigdeal.co.il / ? CampaignId = 873 & sId = 10 ">
<a class = "tavo_button"
data-provider = "bigdeal"
href = "http : //www.bigdeal.co.il/?CampaignId=873&sId=10"
target="_blank"
rel = "nofollow">תבוא!</a>
</div>
</div>
</div>
我试图实现所有目标
< div class = "discount_tools" >
属性在其子节点和
<a class="tavo_button" data-provider="bigdeal" href=
这是我的解决方案:
var nodes = doc.DocumentNode.SelectNodes("//div[@class=\"discount_tools\"]");
var linksCollections = nodes.Select(node => node.Descendants("a"));
List<string> Locations = new List<string>();
List<string> Categories = new List<string>();
List<string> Hrefs = new List<string>();
foreach (var col in linksCollections)
{
string location, category, href;
location = GetAtt("data-address",col);
if (!string.IsNullOrEmpty(location))
{
category = GetAtt("data-kind", col);
if (!string.IsNullOrEmpty(category))
{
href = GetAtt("data-provider", "href", col);
if (!string.IsNullOrEmpty(href))
{
Locations.Add(location);
Categories.Add(category);
Hrefs.Add(href);
}
}
}
}
var nodes=doc.DocumentNode.SelectNodes(“//div[@class=\“折扣工具\”]”);
var linksCollections=nodes.Select(node=>node.substands(“a”);
列表位置=新列表();
列表类别=新列表();
List Hrefs=新列表();
foreach(链接集合中的变量列)
{
字符串位置、类别、href;
位置=GetAtt(“数据地址”,col);
如果(!string.IsNullOrEmpty(位置))
{
类别=GetAtt(“数据类型”,col);
如果(!string.IsNullOrEmpty(类别))
{
href=GetAtt(“数据提供者”,“href”,col);
如果(!string.IsNullOrEmpty(href))
{
位置。添加(位置);
类别。添加(类别);
添加(href);
}
}
}
}
<a class="tavo_button" data-provider="bigdeal" href=
var nodes = doc.DocumentNode.SelectNodes("//div[@class=\"discount_tools\"]");
var linksCollections = nodes.Select(node => node.Descendants("a"));
List<string> Locations = new List<string>();
List<string> Categories = new List<string>();
List<string> Hrefs = new List<string>();
foreach (var col in linksCollections)
{
string location, category, href;
location = GetAtt("data-address",col);
if (!string.IsNullOrEmpty(location))
{
category = GetAtt("data-kind", col);
if (!string.IsNullOrEmpty(category))
{
href = GetAtt("data-provider", "href", col);
if (!string.IsNullOrEmpty(href))
{
Locations.Add(location);
Categories.Add(category);
Hrefs.Add(href);
}
}
}
}
String dataAddressValue = doc.DocumentNode.SelectSingleNode("//div[@class='discount_tools']/ul/li/a[@class='show-location']").Attributes["data-address"].Value;
String LinkHrefValue = doc.DocumentNode.SelectSingleNode("//div[@class='discount_tools ']/link[@rel=’prerender’]").Attributes["href"].Value;