如何将变化的网页存储在变量中? [英] How to store a changing webpage in a variable?

查看:94
本文介绍了如何将变化的网页存储在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本可以自动完成学校中针对团体项目的房间预订过程.我创建了一个自动登录脚本,该脚本运行良好.现在,我想从已加载的页面访问不同的元素(复选框,单选按钮...).

My script automates the room booking process at my school for group projects. I have created an automatic log-in script which works fine. Now I would like to access different elements from the loaded page (check boxes, radio buttons...).

如何保存登录页面中的各种元素并对其执行某些操作?

How can I save various elements from the page that I have logged-in into and perform certain actions on them?

Func SignIn()
    Global $window = _IECreate("https://roombooking.au.dk/classes/Login.aspx?    ReturnUrl=%2fclasses%2fbook.aspx")
    _IELoadWait($window)
    If @error Then Return
    WinSetState("[ACTIVE]", "", @SW_MAXIMIZE)

    Local $username = _IEGetObjByName($window,"ctl00$Main$UsernameBox")
    Local $password = _IEGetObjByName($window,"ctl00$Main$PasswordBox")
    Local $button  = _IEGetObjByName($window, "ctl00$Main$LoginBtn")

    _IEFormElementSetValue($username,"abc")
    _IEFormElementSetValue($password,"123")
    _IEAction ($button, "click")
EndFunc

Func Room()
    Local $SelectRoom = _IEGetObjByName(**???**,"ctl00$Main$ChangeReqsBtn")
    _IELoadWait($bwindow)
    _IEAction($s526,"click")
EndFunc

推荐答案

从帮助文件:

#include <IE.au3>
_IEGetObjByName ( ByRef $oObject, $sName [, $iIndex = 0] )

$ oObject InternetExplorer.Application,Window或Frame对象的对象变量

$oObject Object variable of an InternetExplorer.Application, Window or Frame object

$ sName 指定要匹配的对象的名称

$sName Specifies name of the object you wish to match

$ iIndex 如果名称出现多次,则通过从0开始的索引指定实例 0(默认值)或正整数返回索引的实例 -1返回指定对象的集合

$iIndex If name occurs more than once, specifies instance by 0-based index 0 (Default) or positive integer returns an indexed instance -1 returns a collection of the specified objects

在您的情况下,代码将类似于:

In your case the code will be something like:

本地$ SelectRoom = _IEGetObjByName($ window,"ctl00 $ Main $ ChangeReqsBtn")

Local $SelectRoom = _IEGetObjByName($window,"ctl00$Main$ChangeReqsBtn")

这篇关于如何将变化的网页存储在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆