to:Hassle Set oCell = oDoc.getElementsByTagName("TD").Item(12) oCell.innerHTML = "Good" & oCell.innerHTML Set oCell = Nothing 我用的就是这句,但就这句不行,表面上看起来是写上去了,但是提交不了。请再帮忙看一下,谢谢了
我那种方法怎么可能不行呢,你相应转换一下就好了 例如: Dim docHtml As mshtml.HTMLDocument Dim Element As mshtml.IHTMLElement docHtml = WebBrowser1.Document Element = docHtml.getElementById("spBCmtAuthor") If Not Element Is Nothing Then Element.setAttribute("value", "姓名") Else Exit Function End If
TO: junki 这个方法对于普通的text是可行的,对于我原贴,这个是不行。 junki可以试一下。谢谢关注
提交Form可以这样使用:ElementForm = docHtml.getElementById("comment_post_form") If Not ElementForm Is Nothing Then Call ElementForm.submit() End If
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click '在调用前,必须Web页面已经完全打开才可以 Call SubmitWebForm(AxWebBrowser1, "spBCmtAuthor", "spBCmtURL", "username", "password", "comment_post_form") End Sub
Private Function SubmitWebForm(ByVal oOpenUrl As Object, ByVal sTagUserName As String, ByVal sTagEmail As String, ByVal sTxtUserName As String, ByVal sTxtPassWord As String, ByVal sTagFormName As String) As Boolean Dim webDoc As Object = oOpenUrl.Document.all Dim webTag As Object Dim lengthTag As Integer = webDoc.length - 1 Try Dim docHtml As mshtml.HTMLDocument Dim ElementForm As mshtml.HTMLFormElement, Element As mshtml.IHTMLElement docHtml = oOpenUrl.Document Element = docHtml.getElementById(sTagUserName) If Not Element Is Nothing Then Element.setAttribute("value", sTxtUserName) Else Exit Function End If Element = docHtml.getElementById(sTagEmail) If Not Element Is Nothing Then Element.setAttribute("value", sTxtPassWord) Else Exit Function End If
ElementForm = docHtml.getElementById(sTagFormName) If Not ElementForm Is Nothing Then Call ElementForm.submit() Return True End If Catch ex As Exception MsgBox(ex.Message) End Try End Function
终于写好了,你用这个VB版的再试试:Option Explicit Private Sub Command3_Click() Call SubmitWebForm(WebBrowser1, "spBCmtAuthor", "spBCmtURL", "spBCmtText", "username", "password", "Content111111111111111111111111111111111111111111111111111", "comment_post_form") End Sub'Junki Beta2(2007-12-4):填写表单的用户名、密码等信息,然后提交表单,模拟实现用户登录 Private Function SubmitWebForm(ByVal oOpenUrl As Object, ByVal sTagUserName As String, ByVal sTagEmail As String, ByVal sTagContent As String, ByVal sTxtUserName As String, ByVal sTxtPassWord As String, ByVal sTxtContent As String, ByVal sTagFormName As String) As Boolean Dim webDoc As Object Set webDoc = oOpenUrl.Document.All Dim webTag As Object Dim lengthTag As Integer lengthTag = webDoc.Length - 1 On Error GoTo ErrMsg '第一种方法,定位元素,然后设置其属性 Dim docHtml As MSHTMLCtl.HTMLDocument Dim ElementForm As MSHTMLCtl.HTMLFormElement, Element As MSHTMLCtl.IHTMLElement Set docHtml = oOpenUrl.Document Set Element = docHtml.getElementById(sTagUserName) If Not Element Is Nothing Then Call Element.setAttribute("value", sTxtUserName) Else Exit Function End If Set Element = docHtml.getElementById(sTagEmail) If Not Element Is Nothing Then Call Element.setAttribute("value", sTxtPassWord) Else Exit Function End If Set Element = docHtml.getElementById(sTagContent) If Not Element Is Nothing Then Call Element.setAttribute("value", sTxtContent) Else Exit Function End If Set ElementForm = docHtml.getElementById(sTagFormName) If Not ElementForm Is Nothing Then Call ElementForm.submit End If Exit FunctionErrMsg: MsgBox (Err.Message) End FunctionPrivate Sub Command1_Click() Call WebBrowser1.Navigate2("http://hi.baidu.com/微迈互联/board") End Sub
真是太感谢了,试过了。还是不行。 留言的那个不是普通的TEXT,测试的时候可以先把 If Not ElementForm Is Nothing Then Call ElementForm.submit End If 这个注释了。如图: http://hi.baidu.com/%CE%A2%C2%F5%BB%A5%C1%AA/album/item/a1c0db3000fe5789a8018e81.html
oCell.innerHTML = "Good" & oCell.innerHTML
Set oCell = Nothing 我用的就是这句,但就这句不行,表面上看起来是写上去了,但是提交不了。请再帮忙看一下,谢谢了
例如:
Dim docHtml As mshtml.HTMLDocument
Dim Element As mshtml.IHTMLElement
docHtml = WebBrowser1.Document
Element = docHtml.getElementById("spBCmtAuthor")
If Not Element Is Nothing Then
Element.setAttribute("value", "姓名")
Else
Exit Function
End If
这个方法对于普通的text是可行的,对于我原贴,这个是不行。 junki可以试一下。谢谢关注
If Not ElementForm Is Nothing Then
Call ElementForm.submit()
End If
所有的getElementById都是针对name来操作,并且
不同类型的按钮有不同的命令
'在调用前,必须Web页面已经完全打开才可以
Call SubmitWebForm(AxWebBrowser1, "spBCmtAuthor", "spBCmtURL", "username", "password", "comment_post_form")
End Sub
Private Function SubmitWebForm(ByVal oOpenUrl As Object, ByVal sTagUserName As String, ByVal sTagEmail As String, ByVal sTxtUserName As String, ByVal sTxtPassWord As String, ByVal sTagFormName As String) As Boolean
Dim webDoc As Object = oOpenUrl.Document.all
Dim webTag As Object
Dim lengthTag As Integer = webDoc.length - 1 Try
Dim docHtml As mshtml.HTMLDocument
Dim ElementForm As mshtml.HTMLFormElement, Element As mshtml.IHTMLElement
docHtml = oOpenUrl.Document
Element = docHtml.getElementById(sTagUserName)
If Not Element Is Nothing Then
Element.setAttribute("value", sTxtUserName)
Else
Exit Function
End If
Element = docHtml.getElementById(sTagEmail)
If Not Element Is Nothing Then
Element.setAttribute("value", sTxtPassWord)
Else
Exit Function
End If
ElementForm = docHtml.getElementById(sTagFormName)
If Not ElementForm Is Nothing Then
Call ElementForm.submit()
Return True
End If Catch ex As Exception
MsgBox(ex.Message)
End Try
End Function
Private Sub Command3_Click()
Call SubmitWebForm(WebBrowser1, "spBCmtAuthor", "spBCmtURL", "spBCmtText", "username", "password", "Content111111111111111111111111111111111111111111111111111", "comment_post_form")
End Sub'Junki Beta2(2007-12-4):填写表单的用户名、密码等信息,然后提交表单,模拟实现用户登录
Private Function SubmitWebForm(ByVal oOpenUrl As Object, ByVal sTagUserName As String, ByVal sTagEmail As String, ByVal sTagContent As String, ByVal sTxtUserName As String, ByVal sTxtPassWord As String, ByVal sTxtContent As String, ByVal sTagFormName As String) As Boolean
Dim webDoc As Object
Set webDoc = oOpenUrl.Document.All
Dim webTag As Object
Dim lengthTag As Integer
lengthTag = webDoc.Length - 1 On Error GoTo ErrMsg
'第一种方法,定位元素,然后设置其属性
Dim docHtml As MSHTMLCtl.HTMLDocument
Dim ElementForm As MSHTMLCtl.HTMLFormElement, Element As MSHTMLCtl.IHTMLElement
Set docHtml = oOpenUrl.Document
Set Element = docHtml.getElementById(sTagUserName)
If Not Element Is Nothing Then
Call Element.setAttribute("value", sTxtUserName)
Else
Exit Function
End If
Set Element = docHtml.getElementById(sTagEmail)
If Not Element Is Nothing Then
Call Element.setAttribute("value", sTxtPassWord)
Else
Exit Function
End If
Set Element = docHtml.getElementById(sTagContent)
If Not Element Is Nothing Then
Call Element.setAttribute("value", sTxtContent)
Else
Exit Function
End If
Set ElementForm = docHtml.getElementById(sTagFormName)
If Not ElementForm Is Nothing Then
Call ElementForm.submit
End If
Exit FunctionErrMsg:
MsgBox (Err.Message)
End FunctionPrivate Sub Command1_Click()
Call WebBrowser1.Navigate2("http://hi.baidu.com/微迈互联/board")
End Sub
留言的那个不是普通的TEXT,测试的时候可以先把 If Not ElementForm Is Nothing Then
Call ElementForm.submit
End If
这个注释了。如图:
http://hi.baidu.com/%CE%A2%C2%F5%BB%A5%C1%AA/album/item/a1c0db3000fe5789a8018e81.html
是text,value或其它的
http://hi.baidu.com/微迈互联/board再顶一下
致以崇高的敬意
---------------
谢谢大家关注 。