VB操作网页元素

VB操作网页元素
2010年01月23日
  用webbrowser打开网页后,网页内的所有元素你都可以通过代码来操作,
  方法是:
  1.根据标记名(tagname)的和元素名name来找到元素,
  2.给元素赋值或是执行相关的事件.
  例1: 给username文本框内填充内容:
  Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  Dim doc
  Dim tg
  Set doc = WebBrowser1.Document
  For i = 0 To doc.All.length - 1
  If (LCase(doc.All(i).tagname)) = "input" Then
  if (LCase(doc.All(i).name)) = "username" then
  Set tg = doc.All(i)
  tg.value=text1.text
  end if
  End If
  Next i
  End Sub
  例2: 找到提交按钮并点击
  Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
  Dim doc
  Dim tg
  Set doc = WebBrowser1.Document
  For i = 0 To doc.All.length - 1
  If (LCase(doc.All(i).tagname)) = "input" Then
  if (LCase(doc.All(i).type)) = "submit" then
  Set tg = doc.All(i)
  tg.click
  end if
  End If
  Next i
  End Sub
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值