Visual Basic 2010 Expressに、IHTMLDocumentオブジェクトを使用してWebページを解析するプロジェクトがあります。Webページを取得するために使用している関数は次のとおりです。
Private Function GetHTML(ByVal url As String)
Dim htmldoc As New HTMLDocument()
Dim ihtml2 As IHTMLDocument2
Dim ihtml3 As IHTMLDocument3
Dim iPersistStream As IPersistStreamInit
iPersistStream = DirectCast(htmldoc, IPersistStreamInit)
iPersistStream.InitNew()
ihtml2 = htmldoc.createDocumentFromUrl(url, vbNullString)
Do Until ihtml2.readyState = "complete"
'required for htmlresult.readyState to transition from "loading" to "complete"
System.Windows.Forms.Application.DoEvents()
Loop
ihtml3 = DirectCast(ihtml2, IHTMLDocument3)
Return ihtml3
End Function
私は基本的にこのようなことを関数でやっています:
ihtml = GetHTML("www.blah.com?getvar1=x&getvar2=y")
ihtml.getElementsByTagName("A")
ihtml.getElementById("myel")
etc, etc...
HTMLドキュメントを取得するときに、URL文字列に加えてPOST変数を含める方法を理解しようとしています。つまり、私は次のようなことができるようになりたいということです。
ihtml = GetHTML("www.blah.com?getvar1=x&getvar2=y",["postvar1=a","postvar2=b"])
したがって、可能であればpost変数を含めることができるように、既存のGetHTML関数を変更したいと思います。そうでない場合は、これを行う別の方法があるかどうかを知りたいと思います。助けてくれる人に感謝します。