要填写网页表单,就要知道网页中各个要填写的项目名称,就需要分析网页。分析网页有好几种方法:
1、直接查看网页的源代码(网页右键有该功能)
在源代码中直接搜索如“用户名”,“密码”等需要填写的项目的文字。找到类似以下的代码
<LABEL class="lb for for-1">用户名</LABEL> <LABEL class="lb for for-2 for-3">手机号</LABEL> <INPUT class=ipt-t id=idInput onblur="fCheckAccount(this);fEvent('blur',this)" onmouseover="fEvent('mouseover',this)" onfocus="fEvent('focus',this)" tabIndex=1 onmouseout="fEvent('mouseout',this)" maxLength=50 name=username autocomplete="off" isfocus="false"> <SPAN class=domain>@163.com</SPAN>
将该代码分段
<LABEL class="lb for for-1">用户名</LABEL> --是显示“用户名”的文字的表格,并不是输入项目
<LABEL class="lb for for-2 for-3">手机号</LABEL> --是显示“用户名”的文字的表格,并不是输入项目
而已INPUT开始的就是需要输入的项目,发现有name=username的代码,意思是用户名就是username,这就是我们要找的。
一般都是找 ID= 或者 name = 。
<INPUT class=ipt-t id=idInput onblur="fCheckAccount(this);fEvent('blur',this)" onmouseover="fEvent('mouseover',this)" onfocus="fEvent('focus',this)" tabIndex=1 onmouseout="fEvent('mouseout',this)" maxLength=50 name=username autocomplete="off" isfocus="false">
2、但是项目多的话,这样找比较麻烦,也可以用VBA代码直接找
引用老狼的代码:http://blog.csdn.net/northwolves/article/details/1809109
Sub show163tags()
Dim i As Byte
With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "http://mail.163.com"
Do Until .Readystate = 4
DoEvents
Loop
On Error Resume Next
For i = 1 To 100
If Len(.Document.Forms(0).All(i).Name) > 0 Then Debug.Print "i=" & i; " name=" & .Document.Forms(0).All(i).Name
Next
End With
MsgBox "ok"
End Sub
3、但是有的项目是没有ID和Name的,就比如163邮箱这个button即没ID又没name。
这个时候可以用到索引号,手工找就不介绍了,直接推荐用Ldy的分析工具
http://club.excelhome.net/thread-377077-1-1.html
参考文章
评论