VB2005でWebBrowserで表示しているページにフレームが3つ存在します。
そのフレームの一つにテーブルがあるのですがその取得が
うまくいきません。
「IFrame内のデータの取得」や
「WebBrowser でリンクをクリックするには?」や
「vb.netでフレーム内にアクセスするには?」等を
参考にさせていただいたのですがだめでした。
VB6では取得できていたのでそれをVB2005で行いたいのです。
動作しているVB6のソースは下記のものです。
お手数ですがよろしくお願いいたします。
Dim wdoc As Object
Dim wTable As Object
Set wdoc = WebBrowser1.Document.Frames.Item(2).Document
For Each wTable In wdoc.getElementsByTagName("TABLE")
If Trim(wTable(0).rows(0).cells(0).innerText) = "No" Then
MsgBox wTable(0).rows(1).cells(0).innerText
Exit For
End If
Next
追記ですみません。
「WebBrowser でリンクをクリックするには?」
(http://madia.world.coocan.jp/cgi-bin/VBBBS/wwwlng.cgi?print+200511/05110095.txt)
で魔界の仮面弁士さんが記載しているサンプルは
VB2005 の System.Windows.Forms.WebBrowser クラスではなく、
VB.NET 2002/2003 から、ActiveX の WebBrowser のサンプルのようなので、
VB2005 の System.Windows.Forms.WebBrowser クラスの動作サンプルが
あればテーブルの取得はできると思うのでもしよろしければ
ご教授お願いいたします。
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AxWebBrowser1.Navigate("http://technique.eweb-design.com/sample/6_2_frame.html")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim doc1 As mshtml.IHTMLDocument2 = DirectCast(AxWebBrowser1.Document, mshtml.IHTMLDocument2)
Dim f As mshtml.FramesCollection = doc1.frames
Dim w As mshtml.IHTMLWindow2 = DirectCast(f.item(1), mshtml.IHTMLWindow2)
Dim doc2 As mshtml.IHTMLDocument2 = w.document
Dim l As mshtml.IHTMLElementCollection = doc2.links
Dim A As mshtml.IHTMLElement = DirectCast(l.item(0), mshtml.IHTMLElement)
A.click()
System.Runtime.InteropServices.Marshal.ReleaseComObject(A)
System.Runtime.InteropServices.Marshal.ReleaseComObject(l)
System.Runtime.InteropServices.Marshal.ReleaseComObject(doc2)
System.Runtime.InteropServices.Marshal.ReleaseComObject(w)
System.Runtime.InteropServices.Marshal.ReleaseComObject(f)
System.Runtime.InteropServices.Marshal.ReleaseComObject(doc1)
End Sub
> VB2005でWebBrowserで表示しているページにフレームが3つ存在します。
> Set wdoc = WebBrowser1.Document.Frames.Item(2).Document
は、
> wdoc = WebBrowser1.Document.Window.Frames(2).Document
で、
#WebBrowser(VB2005)のFramesはWindowに属している・・・
> wTable(0).rows(0).cells(0).innerText
は、
> wTable.children(0).children(0).children(0).innerText
とか・・・
#<TABLE>の構造は、<TBODY><TR><TD>〜 なので・・・
大吉末吉さんありがとうございました。
取得することができました。
後は<TABLE>構造をみて children を調整してみます。
ツイート | ![]() |