1

HTML Agility Pack を使用して、Windows ストア アプリの Web サイトをスクレイピングしています。Windows 8 ストア アプリのバージョンは XPath をサポートしておらず、selectNodes 関数もありませんが、必要な値を検索するためのラムダ式をサポートしています。

Web を広範囲に検索した後、私が (何度も何度も) 目にする唯一の解決策は、 DocumentNode.Descendants() を使用して、検索対象の要素のリストを取得することです。ただし、私にとっては、DocumentNode.Descendants() は常に null 値を返します。これは、関数にパラメーターを渡すかどうかに関係なく発生します。

でも返事は返ってきます。HtmlDocument オブジェクト内のページの html を確認できます。

コードスニペット:

HttpContent loginContent = new FormUrlEncodedContent(new[]
{
         new KeyValuePair<string, string>("name", username),
         new KeyValuePair<string, string>("password", password)
}

HttpResponseMessage response = await httpClient.GetAsync(httpClient.BaseAddress); //Gets the cookie

response = await httpClient.PostAsync(loginPageAddress, loginContent); //Logs in
HtmlDocument doc = new HtmlDocument();
doc.Load(new StringReader(await response.Content.ReadAsStringAsync())); // Loads doc, can see html for the page in doc.text attribute now


HtmlNode pointsNode = doc.DocumentNode.Descendants("div").Where(o => o.Attributes["class"].Value == "availableNumber").FirstOrDefault(); // fails because Descendants returns null values

私の即時ウィンドウでのデバッグから:

doc.DocumentNode.Descendants("div")
{HtmlAgilityPack.HtmlNode.Descendants}
    name: null
    System.Collections.Generic.IEnumerator<HtmlAgilityPack.HtmlNode>.Current: null
    System.Collections.IEnumerator.Current: null

この問題を解決する助けがあれば大歓迎です! 皆さんありがとう。

4

0 に答える 0