[英]Include post variables in a createDocumentFromUrl call in .NET
I have a project in Visual Basic 2010 Express that parses web pages use the IHTMLDocument object. 我在Visual Basic 2010 Express中有一个项目,该项目使用IHTMLDocument对象解析网页。 Here is the function I am using to retrieve a web page: 这是我用来检索网页的功能:
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
I'm basically doing stuff like this with the function: 我基本上是用函数来做这样的事情:
ihtml = GetHTML("www.blah.com?getvar1=x&getvar2=y")
ihtml.getElementsByTagName("A")
ihtml.getElementById("myel")
etc, etc...
I'm trying to figure out how I can include POST variables in addition to the URL string when I retrieve the HTML document. 我试图弄清楚在检索HTML文档时如何在URL字符串之外包括POST变量。 By which I mean I'd like to be able to something like this: 我的意思是说我希望能够做到这一点:
ihtml = GetHTML("www.blah.com?getvar1=x&getvar2=y",["postvar1=a","postvar2=b"])
So I'd like to modify my existing GetHTML function in order to allow me to include post variables if that is possible and if not I'd like to know if there is perhaps another way to do this. 因此,我想修改我现有的GetHTML函数,以便在可能的情况下包括post变量,如果不能的话,我想知道是否还有另一种方法可以做到这一点。 Thanks to anyone who can help. 感谢任何能提供帮助的人。
Ok, I would have used WebCilent or WebRequest but... if you're committed to this design: 好的,我会用过WebCilent或WebRequest,但是...如果您致力于这种设计:
You have to navigate to the page, find each input field, set the value then call InvokeMember on the button for that page. 您必须导航到页面,找到每个输入字段,设置值,然后在该页面的按钮上调用InvokeMember。 WebBrowser is all about automating a web browser, not so much about making HTTP requests programatically. WebBrowser的全部目的在于使Web浏览器自动化,而不仅仅是以编程方式发出HTTP请求。
Sample code: http://muftisubzero.blogspot.com/2010/12/playing-with-webbrowser-class-cnet.html 示例代码: http : //muftisubzero.blogspot.com/2010/12/playing-with-webbrowser-class-cnet.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.