0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

メメントモリを楽しく!アプリを作ってみよう!(キャラ情報2)

0
Last updated at Posted at 2025-08-15

キャラ情報からほしいアイテム取り出す

各キャラ情報は、一覧形式になっているので、この構造をたどる。

構造の構成まとめ

タグで構成されてる。
※役割の欄は、個人的な理解のためのコメントです。

タグ 役割
<table> 一覧を構成
<tbody> 一覧の外枠
<trow> 一覧の各行
<td> 各行の項目
<a href> 項目の詳細

構成のアイテム取り出し

<table>を取り出すには「HtmlAgilityPack.HtmlDocument」が用意したメソッドを使う。

var nodes = doc.DocumentNode.SelectNodes(xpath);

これで、一覧の内容を一式とれたことになるらしい。

<tbody>の取り出しは、こんな感じ。

var tbody = table.SelectSingleNode(xpath);

<trow>の取り出しは、いろいろ方法があるらしいが、一番簡単なのは、こんな感じ。

foreach (var trow in tbody.ChildNodes) {
:
}

キャラ名とかレアリティは、こんな感じ。

foreach (var tcol in trow.SelectNodes("td")) {
    name = tcol.InnerText.Trim();
    rarity = tcol.InnerText.Trim();
}

最後に、キャラ画像。

imgNode = tcol.SelectSingleNode(xpath);
lazySrc = imgNode.GetAttributeValue([アトリビュート名], "");

HtmlAgilityPack は機能が豊富のようで、もっと最適な手順で取り出せるらしいが、こぱちゃんからの説明が理解できなかった。

キャラ一覧表示

キャラ情報が取り出せたので、これを一覧形式で表示したい。
DataGridView へ展開します。

つづく。
https://qiita.com/puyon/items/5c236679e4e96cef7bf4

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?