vb 获取网页文本框内容

2025-01-06 12:21:48
推荐回答(2个)
回答1:

private sub command1_click
text1=webBrowser1.document.getelementbyid("1").value
或:
text1=webBrowser1.document.getelementsbyname("1")(0).value
end sub
可把上述代码写到WebBrowser1_DownloadComplete事件中
需要将ID设为唯一的,如果有多个tag的ID为"1"(这是网页设计所不允许但不是完全限制的),无法用getelementbyid,但可用getelementsbyname,如:


其他可用的方法:
text1=WebBrowser1.Document.getelementbyid("123").children(1).Value',否则将无法识别children
text1=WebBrowser1.Document.getelementbyid("123").getelementsbytagname("input")(0).Value
还可用for each obj in WebBrowser1.Document.all来循环判断。

回答2:

Private Sub Command1_Click()
Dim ss As String
ss = Text2.Text 'Text2中放你的网页源码

Dim i As Integer, j As Integer
i = InStr(ss, "form id")
ss = Mid(ss, i)
i = InStr(ss, "name")
j = InStr(ss, "method")
Text1.Text = Mid(ss, i, j - i - 1)
End Sub