vb2005でwebbrowserに表示したテーブルタグの値を取得する方法

このQ&Aのポイント
  • vb2005でWebBrowserコントロールを使用してHTML文書のテーブルタグの値を取得する方法を教えてください。
  • HTML文書にはテーブルタグがあり、その中の【xyz】という値を取得したいです。使用するクラスはvb2005で提供されている2.0のクラスです。
  • WebBrowserコントロールで指定されたHTML文書を読み込み、テーブルタグの中から【xyz】の値を取得する方法を教えてください。文字列操作をせずに解決したいです。
回答を見る
  • ベストアンサー

vb2005でwebbrowserに表示したテーブルタグの値を取得したい。

<head> <meta http-equiv="Content-Type" content="text/html; charset=shift_jis" /> <title>無題ドキュメント</title> </head> <body> <table width="450" border="1"> <tr> <th scope="col">&nbsp;</th> <th scope="col">&nbsp;</th> </tr> <tr> <th scope="row">&nbsp;</th> <td><table width="450" border="1"> <tr> <th scope="col">&nbsp;</th> <th scope="col">&nbsp;</th> </tr> <tr> <th scope="row">&nbsp;</th> <td>【xyz】</td> </tr> </table></td> </tr> </table> </body> </html> このようなhtml文書があったとして、 【xyz】この値を取得したいのですが WebBrowser1.Navigate("上記のhtml文書のURL") Do While (WebBrowser1.IsBusy Or WebBrowser1.ReadyState <> WebBrowserReadyState.Complete) My.Application.DoEvents() System.Threading.Thread.Sleep(50) Loop からどのようにコーディングすれば取得できるんでしょうか?できるだけ文字列操作をするのではなくて、 用意された2.0のクラス群を利用して取得したいんです。教えてください。お願いします。

  • mixiho
  • お礼率41% (251/608)

質問者が選んだベストアンサー

  • ベストアンサー
  • KenKen_SP
  • ベストアンサー率62% (785/1258)
回答No.1

私の環境は VB6.0 で、.NET は触ったことがありませんので、記述が違う かもしれません。 > 【xyz】この値を取得したいのですが ちょっと意味が良く分かってませんが、、 サンプルの HTML ソースは複合表になってますけど、基本はこんな感じで どうですか? Dim t As HTMLTable Dim c As HTMLTableCell Dim lngCno As Long, lngTno As Long For Each t In WebBrowser1.Document.all.tags("table")   lngCno = 0   For Each c In t.Cells '--> getElementsByTagName("td")     lngCno = lngCno + 1     Debug.Print "【Cells(" & lngCno & ") in Tables(" _           & lngTno & ") innerHTML】"     Debug.Print c.innerHTML   Next c   lngTno = lngTno + 1 Next t

mixiho
質問者

お礼

お返事ありがとうございます。 なるほどそうやってやるんですか。 もやもやしてたイメージがはっきりしました。 【xyz】っていうのは単純にりんごでもごりらでもなんでもいいんです。つまり <td>りんご</td>だったらりんごを取得したいんです。<td>ごりら</td>を取得して変数に格納したいんです。ですがサンプルの方でうまくできそうです、ありがとうございました。

関連するQ&A

  • tableの外枠をCSSで表示させない方法

    HTMLで作ったテーブルの外枠の縦線をCSSで表示させないようにしたいのですが可能でしょうか? HTMLはさわらずにできる限りCSSでやりたいと思い、いろいろ試してみましたがうまくいきませんでした。 線種はsolidを使いたいです。 よろしくお願いいたします。 <html> <head> <title>css table</title> <style type="text/css"> <!-- table.sample { width:550px; height:auto; border:solid 1px; border-collapse:collapse; border-left:none; border-right:none; } .sample th { width:100px; border:solid 1px; } .sample tr { border:solid 1px; } .sample td { border:solid 1px; } --> </style> </head> <body> <table class="sample" frame="hsides"> <tr> <th scope="row">&nbsp;</th> <td>&nbsp;</td> <td></td> <td></td> </tr> <tr> <th scope="row">&nbsp;</th> <td>&nbsp;</td> <td></td> <td></td> </tr> <tr> <th scope="row">&nbsp;</th> <td>&nbsp;</td> <td></td> <td></td> </tr> <tr> <th scope="row">&nbsp;</th> <td>&nbsp;</td> <td></td> <td></td> </tr> <tr> <th scope="row">&nbsp;</th> <td>&nbsp;</td> <td></td> <td></td> </tr> </table> </body> </html>

    • ベストアンサー
    • CSS
  • 動的なtableの値を取得したい

    いつもお世話になります。 見よう見まねでやっている超初心者です。 下記の様なテーブル(phpで読み込んでいますので実際は動的です。) の回答ボタンをクリックすると テーブル下の<INPUT type="text" name="kotae">に ボタンをクリックされた行のb列の値を入れたいと思っています。 function kaito()をどのように書いたら取得できるか悩んでいます。 初心者なもので具体的な回答でしたら助かります。 ご教授の程どうぞよろしくお願い致します。 <html> <head> <meta content="text/html; charset=utf-8" /> <script> </script> </head> <body> <table width="100" border="1"> <tr> <th width="30" scope="col">a</th> <th width="30" scope="col">b</th> <th width="40" scope="col">c</th> </tr> <tr> <td>1</td> <td>2</td> <td><input type="button" value="回答" onclick="kaito()"/></td> </tr> <tr> <td>5</td><td>3</td> <td><input type="button" value="回答" onclick="kaito()"/></td> </tr> <tr> <td>5</td> <td>4</td> <td><input type="button" value="回答" onclick="kaito()"/></td> </tr> <tr> <td>5</td> <td>5</td> <td><input type="button" value="回答" onclick="kaito()"/></td> </tr> </table> <INPUT type="text" name="kotae" size="12" > </body> </html>

  • ファイルの内容が表示できるか?

    外部ファイルでお願いします。 参照ボタンから、何でもいいのでファイルを選びます。ファイル名がテキストボックスに表示されます。 下にあるYESボタンを押すと、その下にコメントアウト してあるテキストボックスが上記のID,ファイル名に追加されテキストボックスの中に参照ボタンから選んだ ファイルが挿入される。また、左のNOボタンを押すと その列が削除されるというやり方は可能でしょうか? <html> <head> <title>画面</title> <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS"> </head> <body> <table> <col width="100"> <col width="100"> <tr> <td> <input type="file" name="file"size="50"> </td> </tr> </table> <table border ="1"> <col width="50"> <col width="200"> <tr> <th>ID</th> <th>ファイル名</th> </tr> </table> <input type="button" name="yes" value="YES"value="" > <!-- <table border="1"> <col width="50"> <col width="200"> <tr> <td><input type="button" name="no"value="NO"value="" ></td> <td><input type="text" name="file" size="40" value=""></td> </tr> </table> --> </body> </html>

  • style=displayでの表示/非表示切り替え

    テーブルで表示させている内容をJavaScriptを使って行ごとに表示/非表示の切り替えができるようにしたのですが、表示させた時、IEでは通常のテーブル表示のように表示されるのですが、FirefoxやSafariでは何故かテーブルの一番左の<tr>要素内に全ての<td>要素が入る形で表示されてしまいます。多分CSSの書き方に関係していると思われるのですが、どなたか分かる方アドバイスをお願い致します。 下記は、コードの抜粋です。 [CSS] (略) #content { padding: 10px 0; width: 780px; float: left; } #inquiry { width: 600px; /* ボックスの幅を指定 */ margin-left: auto; margin-right: auto; } #inquiry table { border-top: 1px solid #CCCCCC; border-bottom: none; border-left: none; border-right: 1px solid #CCCCCC; font-size: 100%; width: 100%; } #inquiry td { border-top: none; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: none; padding: 10px; text-align: center; } #inquiry th { border-top: none; border-bottom: 1px solid #CCCCCC; border-left: 1px solid #CCCCCC; border-right: none; background-color: #F3F3F3; font-weight: normal; padding: 10px; } (略) [HTML] (略) <script type="text/javascript" src="../../webroot/js/prototype.js"></script> <script type="text/javascript"> <!-- function OnScreenHelp(id){ var elem = document.getElementsByClassName(id); for(var i=0;i<elem.length;i++) { elem[i].style.display = elem[i].style.display == "none" ? "block" : "none"; } } //--> </script> (略) <table border="border" summary="購入履歴" cellspacing="0"> <caption><h3>購入履歴</h3></caption> <tr> <th scope="col"><label for="name">注文番号</label></th> <th scope="col"><label for="name">ご注文日</label></th> <th scope="col"><label for="name">合計金額</label></th> <th scope="col"><label for="name">備考</label></th> </tr> <?php foreach($data1 as $row1) { $id = $row1['Order']['id']; ?> <tr onclick="OnScreenHelp(<?php echo $id; ?>)"> <td><?php echo h($row1['Order']['id']); ?></td> <td><?php echo h($row1['Order']['orderdate']); ?></td> <td><?php echo h($row1['Order']['total']); ?></td> <td><input type="text" name="name" size="30" id="name" class="text1" value="送料込み" /></td> </tr> <?php } ?> </table><br /> <table border="border" summary="明細情報" cellspacing="0"> <caption><h3>明細</h3></caption> <tr> <th scope="col"><label for="customerno">商品番号</label></th> <th scope="col"><label for="name">商品名</label></th> <th scope="col"><label for="price">価格</label></th> <th scope="col"><label for="quantity">数量</label></th> <th scope="col"><label for="subtotal">小計</label></th> </tr> <?php foreach($data2 as $row2) { $id = $row2['Orderitem']['order_id']; ?> <tr class="<?php echo $id; ?>" style="display:none;"> <td><?php echo h($row2['Product']['productno']); ?></td> <td><?php echo h($row2['Product']['name']); ?></td> <td><?php echo h($row2['Product']['price']); ?></td> <td><?php echo h($row2['Orderitem']['quantity']); ?></td> <td><?php echo h($row2['Orderitem']['subtotal']); ?></td> </tr> <?php } ?> </table> (略)

    • ベストアンサー
    • CSS
  • エクセルでのHTMLの表の切替(行・列切替も)

    こんにちは。 お世話になります。 ショッピングサイトで表示中のサイズ表を新たなデザインに変えることにしました。 具体的には下記に記載の通りです。 元は横に伸びる表記だったものをこのタイミングで縦に伸びる表記に変えます。 また、デザインもよりシンプルなものになります。 このアイテム1点であればこれにて作業完了なのですが、 1000点ともなると、仕組みを作った方がはるかに早いのですが、 手法が頭に浮かびません。 新レイアウトにするのは、エクセル上でひな形の表を作って、それをマクロでボタンを押せば 一気にHTMLのTABLEタグ付きで出力すればイケるかも、と思いました。 ではそのひな形の表を現在のHTMLタグから起こすには… 想像ができませんでした。 それともそもそもまったく違う手法の方が簡易…?難しいです。 よろしければご教示いただけないでしょうか。 ちなみに袖丈があるものもあったり、アイテムによって形状・揃えているサイズ展開が違うため、 テーブルの行や列はアイテムによって変わってきてしまい、○行○列のものです、と いうことはできません。 -------------------- ※現在のサイズ表である↓を <font color=#000000 size=3><b>サイズ表</b></font><br><table width=300 cellspacing=0 cellpadding=2 bgcolor=#FFFFFF><tr><td bgcolor=#66CC66><table width=100% cellspacing=1 cellpadding=1 bgcolor=#FFFFFF><tr><td bgcolor=#99CC99><table width=100% cellspacing=0 cellpadding=20 bgcolor=#FFFFFF><tr><td bgcolor=#FFFFFF align=left><font color=#000000 size=3><table border=1 width=420><tr><td width=60></td><td width=60>92cm</td><td width=60>98cm</td><td width=60>104cm</td><td width=60>110cm</td><td width=60>116cm</td><td width=60>122cm</td></tr> <tr><td width=60>総丈</td><td width=60>54cm</td><td width=60>57cm</td><td width=60>60cm</td><td width=60>63cm</td><td width=60>66cm</td><td width=60>69cm</td></tr> <tr><td width=60>身幅</td><td width=60>26cm</td><td width=60>27cm</td><td width=60>28cm</td><td width=60>29cm</td><td width=60>30cm</td><td width=60>31cm</td></tr></table><br>※平置きでの採寸になるので、若干の誤差はご了承ください。<br></font></td></tr></table></td></tr></table></td></tr></table> 新しい以下のサイズ表表記に切り替えたいです。 【サイズ表】 <table> <tr> <th scope="row">年齢・身長</th> <th scope="row">総丈</th> <th scope="row">身幅</th> </tr> <tr> <th scope="row">92cm</th> <td>54cm</td> <td>26cm</td> </tr> <tr> <th scope="row">98cm</th> <td>57cm</td> <td>27cm</td> </tr> <tr> <th scope="row">104cm</th> <td>60cm</td> <td>28cm</td> </tr> <tr> <th scope="row">110cm</th> <td>63cm</td> <td>29cm</td> </tr> <tr> <th scope="row">116cm</th> <td>66cm</td> <td>30cm</td> </tr> <tr> <th scope="row">122cm</th> <td>69cm</td> <td>31cm</td> </tr> </table> ※平置きでの採寸になるので、若干の誤差はご了承ください。 <br> ちなみに、新しいサイズ表は、サイズ表以外の他の商品情報とともに 以下のスタイルで定義されています。 <style> .sc-table-01{width: 320px;font-size: 0.9em;} .sc-table-01 table{ border-collapse:collapse; margin: 5px; width: 100%; } .sc-table-01 th{ font-style: normal; font-size: 0.9em; color: #000; background-color: #FFD6C1; border: 1px solid #999; padding: 6px; white-space: nowrap; line-height: 150%; } .sc-table-01 td{ border: 1px solid #999; font-size: 0.9em; padding: 10px; line-height: 150%; } </style> <div class="sc-table-01">

  • テーブルのレイアウトがおかしくなる

    畏れ入ります。 テーブルを作っているのですが奇妙な現象にあっています。 <table border="1" width="100%"> <tr> <th width="18">&nbsp;</th> <th width="100">&nbsp;</th> <th>&nbsp;</th> <th width="100">&nbsp;</th> </tr> <tr> <td rowspan="2">&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> <td>&nbsp;</td> </tr> <tr> <td colspan="3">&nbsp; <!-- ここに たくさんの 文字列を入れると ・・・ --> </td> </tr> </table> このコメントの部分が無い状態では正常にでていますが、 ここにたくさんの文字列(半角30文字程度でおかしくなります)を投入すると、レイアウトが異常に崩れてしまいます。 文字列は改行してもかまわないのですが テーブル1行目2行目のセルサイズ(width)がこのように変化してしまうと困るのです。 どのようにしたら良いか(width=100の部分を守らせたい) 教えてください。

    • ベストアンサー
    • HTML
  • CSSのテーブルについて教えて下さい。

    テーブルなのですがh1が適用されません。 又表の枠線が黒になりません。 また(休診)を赤にしたいのですが表示されません。 どこをどう直したらいいのか教えて下さい。 お願いします。 h1 { margin: 1em 0; padding: 0.3em; border: 1px silver solid; background: url(../image/subpage_h2_bg.gif) bottom repeat-x; color: gray; font-weight: bold; font-size: large; } /*hyou*/ caption{ color: #996666; padding-bottom: 14px; text-align: center; } table{ width: 800px; border: solid 2px ; border-collapse: collapse; } th,td { padding: 5px; border: solid 1px #000000; text-align:center; } th { background-color:silver; font-weight: bold; } td.col01{ font-weight: bold; background-color:silver; } em { color: red; font-weight: bold; } /* テーブル列幅指定 */ .cola { width:100px; } .col01{ width: 100px; } .col02{ width: 70px; } .col03{ width: 70px; } .col04{ width: 70px; } .col05{ width: 70px; } .clo06{ width: 70px; } .style1 {margin-left:1em; } HTML <h1>外来診療のご案内</h1> <table> <caption>外来診療 予定表</caption> <tr> <th class="a">診察科</th> <th class="b">月</th> <th class="c">火</th> <th class="d">水</th> <th class="e">木</th> <th class="f">金</th> <th class="g">土</th> <th class="h">日</th> </tr> <tr> <th class="col01">一般歯科</th> <td class="col02" rowspan="4"><em>休診</em></td> <td class="col03" colspan="5">◯</td> <td class="col04" rowspan="4"><em>休診</em></td> </tr> <tr> <th class="col01">小児歯科</th> <td class="col02">◯</td> <td class="col03">&nbsp;</td> <td class="col04">◯</td> <td class="col05">&nbsp;</td> <td class="col06">◯</td> </tr> <tr> <th class="col01">歯列矯正</th> <td class="col02">&nbsp;</td> <td class="col03">◯</td> <td class="col04">&nbsp;</td> <td class="col05">◯</td> <td class="col06">&nbsp;</td> </tr> <tr> <th class="col01">審美歯科</th> <td class="col02">&nbsp;</td> <td class="col03">◯</td> <td class="col04">&nbsp;</td> <td class="col05">&nbsp;</td> <td class="col06">◯</td> </tr> </table>

    • ベストアンサー
    • HTML
  • FC2のブログで HTML

    新規投稿した際に、画像のソース下にテーブルを配置したのですが、画像とテーブルの間に広い空白ができてしまいます。空白をなくすにはどのようにすればよいのでしょうか? <a href="http://blog-imgs-37.fc2.com/h/i/r/xxx/xxx-img600x448-1291282057iczrmy28164.jpg" target="_blank"><img src="http://blog-imgs-37.fc2.com/h/i/r/xxx/xxxi-img600x448-1291282057iczrmy28164s.jpg" alt="" border="0" width="119" height="89" /></a> <table width="400" border="1"> <tr> <th scope="col">価格A</th> <th scope="col">価格B</th> <th scope="col">価格C</th> </tr> <tr> <td>1,500</td> <td>2,000</td> <td>未</td> </tr> </table>

    • ベストアンサー
    • HTML
  • CSSについて 初心者です。

    勉強中の身なんですが・・ このように設定した場合文章1と文章2が大きく開く状態になるんですが、なぜでしょうか? また文章1セルの真ん中に表示され文章2が左にひょうじされるのも分りません・・・・ いろいろ調べてみたんですが中々納得ができなくて・・・ 特にこうういう風にやりたいとかは特になくて、なんでこうなるのかが知りたいのです。 詳しい方説明して頂けるとありがたいです。すみませんがよろしくお願い致しますm(。。)m 「HTML」 <table> <tr> <th>見出し</th> <th></th> <th>&nbsp;</th> <th>&nbsp;</th> </tr> <tr> <td>内容</td> <td>&nbsp;</td> <td>&nbsp;</td> <td></td> </tr> </table> 「CSS] table{ width:250px; border-collapse:collapse; border-width:1px; border-style:solid; border-color:#000000; border-spacing:0; } th{ border-width:1px; border-style:solid; border-color:#000000; } td{ border-width:1px; border-style:solid; }

    • ベストアンサー
    • HTML
  • テーブルのテーブルの間に間ができるのでしょうか?

    はじめまして、超html初心者のものです。 なぜ同じようテーブルを3つ書いているのに一番上のテーブルと真ん中のテーブルの間が開いてしまっているのかがわかりません。 あと、一番上のテーブルの-から先をもう少し左に寄せることもうまくいきません。 なにかアドバイスをよろしくお願いします。 ↓これがソースです。 <html> <head><title>test</title> </head> <form> <table border=1 cellspacing=0 cellpadding=2 width=760> <tr> <th width=95 height=30 align="right">日付け:</th> <td width=284> <input type="text"><input type="button"> </td> <td>&nbsp;-&nbsp;</td> <td><input type="text"><input type="button"></td> </tr> </table> <table border=1 cellspacing=0 cellpadding=2 width=760> <tr> <th width=95 height=30 align="right">部署:</th> <td width=100> <select name="busyo"></select> </td> <th width=80 align="right">営業所:</th> <td width=100> <select name="eigyousyo"></select> </td> <th width= 80 align="right">担当コード:</th> <td width=450> <select name="tantocode"></select> </td>   </tr> </table> <table border=1cellspacing=0cellpadding=2width=760> <tr> <th width=80 align="right">権限:</th> <td width=700> <select name="kengen"></select> </td> </tr> </table> </form> </html>

専門家に質問してみよう