本次介紹的方法是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 "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 |
新跟帖 (共1 條評論)
查看更多評論。。。