登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

凌晨阳光

 
 
 

日志

 
 

VBA-填写网页表单的方法  

2011-08-04 12:47:32|  分类: Excel自动化 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

本次介绍的方法是http://chiensq.blog.163.com/blog/static/1035628201174015765/?newFollowBlog中介绍的第二种方法控制网页

要填写网页表单,就要知道网页中各个要填写的项目名称,就需要分析网页。分析网页有好几种方法:

以:http://mial.163.com/为例

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

 

参考文章

http://club.excelhome.net/thread-719242-1-1.html

  评论这张
 
阅读(3683)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018