How to store a changing webpage in a variable?

喜夏-厌秋 提交于 2019-12-13 00:52:45

问题


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

回答1:


From the Help File:

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

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

$sName Specifies name of the object you wish to match

$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:

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




回答2:


AutoIt offers many different approaches to HTML document retrieval. Without providing concerning source code it can only be guessed.

HTML source of document is returned by _IEDocReadHTML() (assuming you're using IE.au3 UDF). Example:

#include <IE.au3>

Global Const $oIE      = _IECreate('http://www.google.com/')
Global Const $sDocHTML = _IEDocReadHTML($oIE)

_IEQuit($oIE)
ConsoleWrite($sDocHTML & @LF)
Exit 0

Mentioned UDF contains functions to set values to form elements (lookup _IEForm...() in AutoIt's user defined function reference).



来源:https://stackoverflow.com/questions/29881127/how-to-store-a-changing-webpage-in-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!