找回密码
 加入
搜索
查看: 12015|回复: 21

[AU3基础] 关于GUI登陆新浪微薄,但是新浪微薄站的网页中没有表单,无法得到相应控件。(已解决)

 火.. [复制链接]
发表于 2010-7-18 23:21:51 | 显示全部楼层 |阅读模式
本帖最后由 yiruirui 于 2010-8-30 09:22 编辑

自己GUI源码如下:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\ocr\form1.kxf
Dim $usename,$password
$Form1_1 = GUICreate("微薄登陆", 633, 447, 193, 125)
$Radio1 = GUICtrlCreateRadio("新浪微薄", 64, 64, 81, 33)
$Radio2 = GUICtrlCreateRadio("腾讯微薄", 159, 64, 81, 33)
$Group1 = GUICtrlCreateGroup("", 16, 104, 369, 297)
$Label1 = GUICtrlCreateLabel("用户账号", 24, 144, 52, 17)
$Label2 = GUICtrlCreateLabel("用户密码", 20, 259, 52, 17)
$input1=GUICtrlCreateInput("", 152, 136, 225, 21)
$input2=GUICtrlCreateInput("", 152, 240, 225, 21,BitOR($ES_LEFT, $ES_AUTOHSCROLL, $ES_LOWERCASE, $ES_PASSWORD))
$Button1 = GUICtrlCreateButton("登陆", 40, 328, 97, 41, 0)
$Button2 = GUICtrlCreateButton("退出", 264, 328, 97, 41, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                case $Button1
                        $usename=GUICtrlRead($input1)                                                        $password=GUICtrlRead($input2)
                        if $password=""Or $usename=""  Then MsgBox(0,"错误","用户名或密码不能为空!")
                case $Button2
                        Exit
                Case $GUI_EVENT_CLOSE
                        Exit
                       

        EndSwitch
WEnd

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd
新浪微薄首页:http://t.sina.com.cn/

#include <IE.au3>
$oIE = _IECreate ("http://t.sina.com.cn/")
$oForms = _IEFormGetCollection ($oIE)
MsgBox(0, "表单信息", "这个页面上共有" & @extended & "个表单")
For $Form In $oForms
MsgBox(0, "表单名称", $Form.name)
$oQuerys = _IEFormElementGetCollection ($Form)
For $Query In $oQuerys
MsgBox(0, "表单控件信息", "名称:"&$Query.name & " 类型:"&$Query.type)
Next
Next
这段代码得不到表单和控件,所以我不知道该如何提交我从GUI中获取的用户名和密码。
看了论坛中的邮箱登陆代码,可以从网页中获取表单和控件,但是这里得不到,我该如何解决?求指点,先谢谢大家!
 楼主| 发表于 2010-7-19 14:22:58 | 显示全部楼层
没人知道吗?就是想问大家如何提交GUI中的数据给新浪微薄网站,如果用户名称和密码都正确,则进入,否则,返回错误信息。
思路是很明朗,但是无从下手!
发表于 2010-7-19 15:10:20 | 显示全部楼层
#include <IE.au3>
$oIE = _IECreate ("http://t.sina.com.cn")

$oUser = _IEGetObjById  ($oIE, "loginname")
$oPass = _IEGetObjById  ($oIE, "password")
_IEFormElementSetValue ($oUser, "thesnoW@sina.com")
_IEFormElementSetValue ($oPass, "FuckSinaEveryday")
$oLogin = _IEGetObjById  ($oIE, "login_submit_btn")
$oLogin.click()
发表于 2010-7-19 15:11:21 | 显示全部楼层
密码的ID也许是password_text,我没有账号,没法测试
发表于 2010-7-19 15:14:42 | 显示全部楼层
本帖最后由 Ziya 于 2010-7-19 15:20 编辑
<div class="loginform" id="login_form">
          <div class="input_bg">
            <input alt="邮箱/会员帐号/手机号" title="邮箱/会员帐号/手机号" style="color: rgb(153, 153, 153);" id="loginname" type="text">
          </div>
          <div class="input_bg">
            <input style="color: rgb(153, 153, 153); display: none;" id="password" type="password">
                        <input id="password_text" style="color: rgb(153, 153, 153);" type="text">
          </div>
          <div class="setting">

         <span class="lf"> <input class="labelbox" id="remusrname" checked="checked" type="checkbox">
              <label>下次自动登录</label></span><a class="rt" href="http://login.sina.com.cn/cgi/getpwd/getpwd0.php?entry=sso" target="_blank">找回密码</a>
          </div>
          <div class="signin"><a href="javascript:void(0);" class="sp" id="login_submit_btn"></a></div>
        </div>


看下代码不就知道id了.....
发表于 2010-7-19 15:20:08 | 显示全部楼层
楼上的,我不看代码,我能说"也许是"吗?
发表于 2010-7-19 15:20:42 | 显示全部楼层
回复 6# thesnow

大哥,我真是对楼主说的,谢谢~
 楼主| 发表于 2010-7-19 16:40:42 | 显示全部楼层
感谢楼上的两位回答,谢谢!
发表于 2010-7-19 17:37:25 | 显示全部楼层
#include
$oIE = _IECreate ("http://t.sina.com.cn")

$oUser = _IEGetObjById  ($oIE, "loginname")
...
thesnow 发表于 2010-7-19 15:10

_IEFormElementSetValue ($oPass, "FuckSinaEveryday")
这句很精彩。
 楼主| 发表于 2010-7-19 19:58:04 | 显示全部楼层
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                case $Button1
                        $usename=GUICtrlRead($input1)
                        ;if $usename="" Then MsgBox(0,"错误","请输入用户名!")
                        $password=GUICtrlRead($input2)
                        if $password=""Or $usename=""  Then  MsgBox(0,"错误","用户名或密码不能为空!")
                        $oIE = _IECreate ("http://t.sina.com.cn",0,0,1,1)
            $oUser = _IEGetObjById  ($oIE, "loginname")
                        $oPass = _IEGetObjById  ($oIE, "password")
            _IEFormElementSetValue ($oUser, "$usename")
            _IEFormElementSetValue ($oPass, "$password")
           $oLogin = _IEGetObjById  ($oIE, "login_submit_btn")
           $oLogin.click()

                       
                case $Button2
                        Exit
                Case $GUI_EVENT_CLOSE
                        Exit
                       

        EndSwitch
WEnd

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

代码改成上面这样了,能够把数据填到对应的表单控件中,最后
$oLogin = _IEGetObjById  ($oIE, "login_submit_btn")
           $oLogin.click()
也点了登陆按钮了,但是这里还有个问题我想不出办法,
如何判断输入的用户名和密码是否正确?当不正确的时候该如何在我的GUI上面返回错误信息呢?
如果正确了又该如何把打开的网页内容显示到我的GUI上面呢?(这里我想把网页嵌入到GUI上,$oIE = ObjCreate("Shell.Explorer.2")可以实现网页嵌入)。
上面的代码点击登陆按钮的时候都把内容给提交了,后续的操作该如何做呢?求大大们给点意见,先谢谢大家了!
 楼主| 发表于 2010-7-20 10:17:20 | 显示全部楼层
我同样又在期待高手的再次出现!要耐心的等待!在等待!
发表于 2010-7-20 12:35:58 | 显示全部楼层
读取网页源码,账号或密码正确和错误两种情况读取应该有区别的,用正则提取关键数据就行了。
 楼主| 发表于 2010-7-20 14:07:44 | 显示全部楼层
读取网页源码,账号或密码正确和错误两种情况读取应该有区别的,用正则提取关键数据就行了。
autoit3CN 发表于 2010-7-20 12:35



    网页源码容易实现,您能说仔细点吗?或者给个简单点的例子让我自己去琢磨?3KS
发表于 2010-7-20 17:57:17 | 显示全部楼层
方法到处是啊,楼主不用心啊.
 楼主| 发表于 2010-7-20 22:33:30 | 显示全部楼层
回复 14# thesnow

感谢你的意见,我在论坛把所有关于IE操作的都浏览了一遍,没有发现类似的问题啊,您能给个链接吗?感激不尽!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-3 12:35 , Processed in 0.160435 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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