0
請原諒我的英語,它不是我的第一語言。C#列表和HtmlParse
第1類是我有我的財產和列表 第2類是我的html解析器。
目前,它的工作是打開網頁並找到鏈接。
現在我遇到的問題是,我想使用Linq,另一個List,或者你認爲最好的。 進行排序studRet(填充NameID)的結果
因此,所有從 「itsupporter」 的 「href發現結果」 是由
Itsupporter
結果
結果
finans
結果排序
結果
我該怎麼做,最好的做法是什麼,有什麼好的例子可以指導我解答?
我不知道如何確保,它找到的鏈接是從右側studRet。
我希望這是一個足夠好的問題。
Class1的
private readonly List<Property> dataList = new List<Property>();
// Get property
internal struct Property
{
public readonly string url;
public readonly string cssTag;
public readonly string studRet;
public readonly int id;
public Property(string url, string cssTag, string studRet, int id)
{
this.url = url;
this.cssTag = cssTag;
this.studRet = studRet;
this.id = id;
}
}
public List<Property> GetList()
{
dataList.Add(new Property("http://elevplads.dk/annoncer?search=It-Supporter", "//div[@class='col-xs-12 col-sm-12 col-md-12']//a", "itsupporter", 1));
dataList.Add(new Property("http://elevplads.dk/annoncer?stillingstype=finans", "//div[@class='col-xs-12 col-sm-12 col-md-12']//a", "finans", 2));
return dataList;
}
2級
public readonly Jobbot Jobdata = new Jobbot();
public void HandleHtml()
{
List<Jobbot.Property> dataList = Jobdata.GetList();
HtmlWeb web = new HtmlWeb();
foreach (var data in dataList)
{
HtmlDocument document = web.Load(data.url);
var nodes = document.DocumentNode.SelectNodes(data.cssTag);
if (nodes != null)
{
foreach (HtmlNode item in nodes)
{
if (item.Attributes.Contains("href"))
{
if (item.Attributes["href"].Value.StartsWith("http://"))
{
Console.WriteLine(item.Attributes["href"].Value);
}
}
}
}
}
} // End
我看着它,你說得對。感謝使它實現它。 – user1979911