私の最初の言葉ではなく、私の英語が間違っています。C#リストとHtmlParse
クラス1は私のプロパティとリストを持っています クラス2は私のhtmlパーサーです。
現時点では、ウェブページを開いて想定されているリンクを見つけることで仕事をしています。
今、問題は、Linq、別のリストを使用したいということです。あなたの意見が一番良いと思います。だから、 "itsupporter" "HREF" から検出されたすべての結果が
Itsupporter
結果
結果
finans
結果
でソートされているstudRet(名前ID)
で結果をソートする 結果
私はこれをどのように行うべきですか、ベストプラクティスとは何ですか、私は答えに導く良い例ですか?
リンクが見つかったかどうかを確認する方法はわかりません。右のスタッドから取得してください。
これは十分な質問です。
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