簡體   English   中英

在.NET中的createDocumentFromUrl調用中包括發布變量

[英]Include post variables in a createDocumentFromUrl call in .NET

我在Visual Basic 2010 Express中有一個項目,該項目使用IHTMLDocument對象解析網頁。 這是我用來檢索網頁的功能:

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"])

因此,我想修改我現有的GetHTML函數,以便在可能的情況下包括post變量,如果不能的話,我想知道是否還有另一種方法可以做到這一點。 感謝任何能提供幫助的人。

好的,我會用過WebCilentWebRequest,但是...如果您致力於這種設計:

您必須導航到頁面,找到每個輸入字段,設置值,然后在該頁面的按鈕上調用InvokeMember。 WebBrowser的全部目的在於使Web瀏覽器自動化,而不僅僅是以編程方式發出HTTP請求。

示例代碼: http : //muftisubzero.blogspot.com/2010/12/playing-with-webbrowser-class-cnet.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM