0

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関数を変更したいと思います。そうでない場合は、これを行う別の方法があるかどうかを知りたいと思います。助けてくれる人に感謝します。

4

1 に答える 1

0

わかりました、私はWebCilentまたはWebRequestを使用したでしょうが... この設計にコミットしている場合:

ページに移動し、各入力フィールドを見つけ、値を設定してから、そのページのボタンで InvokeMember を呼び出す必要があります。WebBrowser は Web ブラウザーの自動化に関するものであり、プログラムによる HTTP 要求の作成に関するものではありません。

サンプルコード: http://muftisubzero.blogspot.com/2010/12/playing-with-webbrowser-class-cnet.html

于 2011-11-28T21:12:21.737 に答える