ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 16832|回复: 15

[求助] VBA登陆WEB163邮箱

[复制链接]

TA的精华主题

TA的得分主题

发表于 2011-5-15 14:05 | 显示全部楼层 |阅读模式
哪位朋友能给指点一下, 如何用VBA代码登陆 163的WEB邮箱?  
用户名和密码可以输入,  就是不知道怎样点那个登陆按钮.  这个按钮我没找到name, 也没id....不知道怎么做了, 哪位朋友可以帮下小弟?

以下是mail.163.com 源代码的一部份:
<form id="login163" method="post" name="login163" action="" onSubmit="return fLoginFormSubmit();">
                                                <input name="verifycookie" type="hidden" value="1" />
                                                <input type="hidden" name="style" id="txtStyle" value="34" />
                                                <input type="hidden" id="product" name="product" value="mail163" />
                                                <input type="hidden" id="savelogin" name="savelogin" value="" />
                                                <input type="hidden" id="url2" name="url2" value="http://mail.163.com/errorpage/err_163.htm">

                                                <div id="uName" class="fi">
                                                        <label class="lb for for-1">用户名</label>
                                                        <label class="lb for for-2 for-3">手机号</label>
                                                        <input id="idInput" tabindex="1" class="ipt-t" type="text" name="username" onFocus="fEvent('focus',this)" onBlur="fCheckAccount(this);fEvent('blur',this)" onMouseOver="fEvent('mouseover',this)" onMouseOut="fEvent('mouseout',this)" maxlength="50"/>
                                                        <span class="domain">@163.com</span>
                                                </div>
                                                <div class="fi">
                                                        <label class="lb">密 码</label>
                                                        <input id="pwdInput" tabindex="2" class="ipt-t" type="password" name="password" onMouseOver="fEvent('mouseover',this)" onFocus="fEvent('focus',this)" onBlur="fEvent('blur',this)" onMouseOut="fEvent('mouseout',this)"/>
                                                        <a class="forget" href="http://reg.163.com/RecoverPasswd1.shtml?from=mail163" target="_blank" title="找回密码" tabindex="8">忘记密码了?</a>
                                                </div>
                                                <div class="fi for for-1">
                                                        <label class="lb">版 本</label>
                                                        <select tabindex="3" name="selType" id="selType">
                                                                <option value="-1" selected="selected">    默   认</option>
                                                                <option value="js35">    极速 3.5</option>
                                                                <option value="jy">    简约 3.0</option>
                                                        </select>
                                                </div>
                                                <div class="fi fi-nolb options for for-1">
                                                        <label for="remUsername" onMouseOver="document.getElementById('autoLoginDiv').style.display=''" onMouseOut="document.getElementById('autoLoginDiv').style.display='none'"><input class="ipt-c" tabindex="4" name="remUser" type="checkbox" id="remUsername" />两周内自动登录</label>
                                                        <a class="autologin" href="http://help.163.com/special/00752CLD/163mail_zddl.html" target="_blank" title="什么是自动登录">什么是自动登录</a>
                                                        <label for="secure"><input class="ipt-c" tabindex="5" name="secure" type="checkbox" id="secure" checked="checked" />SSL安全登录</label>
                                                        <div style="position:absolute;z-index:9; width:180px; height:35px;*height:36px; background-color:#ffefa4; border:1px #FF9900 solid; left: 47px; top: 22px; text-align:left; padding:5px; line-height:150%; color:#dc6800; display:none" id="autoLoginDiv">为了您的信息安全,请不要在网吧或公用电脑上使用此功能!</div>
                                                </div>
                                                <div class="fi fi-nolb">
                                                        <button class="btn btn-login" onMouseOver="this.className+=' btn-login-hover'" onMouseDown="this.className+=' btn-login-active'" onMouseOut="this.className='btn btn-login'" onMouseUp="this.className='btn btn-login'" tabindex="6" type="submit" onClick="if(window.location.href.indexOf('#return') == -1){setCookie('ntes_mail_firstpage','normal');}saveLoginType();">登 录</button>
                                                        <a class="btn btn-reg for for-1" tabindex="8" href="http://reg.email.163.com/mailregAll/reg0.jsp?from=163mail_right" target="_blank">注 册</a>
                                                        <button class="btn btn-regsjy for for-2" tabindex="8" type="button" onClick="fShowPhoneReg(true);">还没设置手机号登录?</button>
                                                </div>
                                        </form>

[ 本帖最后由 lxlzmh2002 于 2011-5-15 14:06 编辑 ]

TA的精华主题

TA的得分主题

发表于 2011-5-15 18:10 | 显示全部楼层

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-5-15 19:47 | 显示全部楼层
狼哥,您的代码小弟多次看到过,非常精僻。
不知道163邮箱改了是怎么的,没有item(35), 这个代码也是不能点到登录,万请指教!

TA的精华主题

TA的得分主题

发表于 2011-5-15 20:49 | 显示全部楼层
曲线救国,从百度:http://www.baidu.com/s?wd=163%D3 ... amp;tn=sogouie_1_dg
登陆不就行了,所有ID或NAME都可以抓取的。

<td class="op_email3_name">用户名:</td><td><input autocomplete="off" id="op_email3_username"  style="color:#ccc;" value="    " onfocus="_op_shequ_clear()"onblur="_op_shequ_added()"  type="text"></td><td>@163.com</td> </tr> <tr> <td class="op_email3_name">密 码:</td><td><input id="op_email3_password" autocomplete="off" type="password"></td> <td><a id="op_email3_fpsw" class="op_email3_fpsw" href="http://reg.163.com/RecoverPasswd1.shtml?from=mail163" onmousedown="return c({'fm':'alop','url':this.href,'p1':_aMC(this),'p2':1})" target=_blank >忘记密码</a></td> </tr>  <tr> <td></td><td colspan=2 style="vertical-align:top"> <a id="op_email3_sub" href="#" onclick="op_email3_submit()" onmousedown="return c({'fm':'alop','url':'http://mail.163.com/','p1':_aMC(this),'p2':0,'p3':0,'p4':1});" >登录</a>

[ 本帖最后由 xmyjk 于 2011-5-15 20:51 编辑 ]

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-5-15 21:45 | 显示全部楼层
多谢弦月,您给的曲线的确可以救得了国
只是不知道是id, 用byID不行,继续用byName返而可以....
Sub mail163()
    Dim ie As InternetExplorer
    Dim d As HTMLDocument
    Dim e As IHTMLElementCollection
    With CreateObject("InternetExplorer.Application")
         .Navigate "http://www.baidu.com/s?wd=163%D3%CA%CF%E4%B5%C7%C2%BD&tn=sogouie_1_dg"
         .Visible = True
         Do Until .readyState = 4
            DoEvents
         Loop
         Set d = .Document
         Set e = d.getElementsByName("op_email3_username")
         e.Item(0).Value = "myccount"
         Set e = d.getElementsByName("op_email3_password")
         e.Item(0).Value = "mypassword"
         Set e = d.getElementsByName("op_email3_sub")
         e.Item(0).Click
    End With
   
    Set e = Nothing
    Set d = Nothing
End Sub

谢谢狼~~ 谢谢月!

TA的精华主题

TA的得分主题

发表于 2011-5-15 22:18 | 显示全部楼层
原帖由 lxlzmh2002 于 2011-5-15 21:45 发表
多谢弦月,您给的曲线的确可以救得了国
只是不知道是id, 用byID不行,继续用byName返而可以....
Sub mail163()
    Dim ie As InternetExplorer
    Dim d As HTMLDocument
    Dim e As IHTMLElemen ...


如果对这方面感兴趣的话,可以学习LDY版主的:http://club.excelhome.net/thread-377077-1-1.html

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-5-15 23:58 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
再次感谢弦月,ldy的一篇文章,特别是他那个分析工具太好用了。 163邮箱这个button即没ID又没name。。。用ldy的分析工具找到索引号,直接用索引号。我改了一下直接通过。 索引号虽然有时候不太靠普,但实在没有地方下爪的时候,用它也挺好^^

Sub mail163()
With CreateObject("InternetExplorer.Application")
.Visible = True
.navigate "http://mail.163.com"
Do Until .Readystate = 4
DoEvents
Loop
.Document.All(64).Value = "myaccount"
.Document.All(70).Value = "mypassword"
.Document.All(86).Click
End With
MsgBox "Ok"
End Sub

TA的精华主题

TA的得分主题

发表于 2011-5-16 00:16 | 显示全部楼层
原帖由 lxlzmh2002 于 2011-5-15 23:58 发表
再次感谢弦月,ldy的一篇文章,特别是他那个分析工具太好用了。 163邮箱这个button即没ID又没name。。。用ldy的分析工具找到索引号,直接用索引号。我改了一下直接通过。 索引号虽然有时候不太靠普,但实在没有地方下 ...


恭喜解决啦
现在没办法,很经常很多网页没有ID和NAME,估计避免恶意软件的批量登陆吧。
找按钮或控件的话,我经常用以下这种方法:
For i = 0 To .Document.forms(1).tags("input").Length - 1
  If InStr(.Document.forms(1).tags("input")(i).Value, "登录") > 0 Then x = i: Exit For
Next
.Document.forms(1).tags("input")(x).Click
有些页面按钮的ITEM号是变动,只能用这种方式。
这个方法还可以用来抓TABLE
    For i = 0 To doc.all.tags("table").Length - 1
        If doc.all.tags("table")(i).innertext Like "*规格/牌号*" Then x = i: Exit For
    Next
或者抓链接(<A>)的时候
    For i = 0 To doc.all.tags("A").Length - 1
        If doc.all.tags("A")(i).innertext Like ">" Then
            y = i
            doc.all.tags("A")(y).Click
        End If
    Next

另外,表单的提交还可以用FORMS(X).SUBMIT,就可以不用去找按钮啦。

无论如何,还是喜欢和楼主这样能主动学习的网友交流,呵呵,授人以鱼不如授之以渔。

[ 本帖最后由 xmyjk 于 2011-5-16 00:35 编辑 ]

TA的精华主题

TA的得分主题

发表于 2011-10-9 23:22 | 显示全部楼层
头像被屏蔽

TA的精华主题

TA的得分主题

发表于 2011-10-10 05:59 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

关闭

最新热点上一条 /1 下一条

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-19 22:35 , Processed in 0.044167 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表