繁体   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