Jump to content
Sign in to follow this  
nirmalsalem

Read content inside div tag of aspx page

Recommended Posts

Hi,

I am trying to read a content inside a div tag of an aspx page.

<div id="EmailField">
    <span id="email">
        <a href="mailto:xxxx@yyyyy.com">xxxx@yyyyy.com</a>
    </span>
</div>

 

I want to extract the mail id inside the <a> under div tag. The webpage is designed as an aspx page.

Please advise.

 

Share this post


Link to post
Share on other sites

Like this ?
 

#include <ie.au3>

_IEErrorHandlerRegister(_User_ErrFunc)
_Example()

Func _Example()
    Local $oIE = _IECreate()

    Local $s_HTML = ""
    $s_HTML &= '<div id="EmailField">' & @CRLF
    $s_HTML &= '    <span id="email">' & @CRLF
    $s_HTML &= '        <a href="mailto : aaaa@yyyyy.com">xxxx@yyyyy.com</a>' & @CRLF
    $s_HTML &= '        <a href="mailto : bbbb@yyyyy.com">xxxx@yyyyy.com</a>' & @CRLF
    $s_HTML &= '    </span>' & @CRLF
    $s_HTML &= '</div>' & @CRLF

    _IEDocWriteHTML($oIE, $s_HTML)

    ; https://www.w3.org/TR/css3-selectors/#selectors
    ; find all A tags with HREF attribute value contains the substring "mailto"
    ;   which are child of SPAN tags with ID="email"
    ;       which are child of DIV tags with ID="EmailField"

    Local $oSelection_coll = _IEquerySelectorAll($oIE,'div#EmailField>span#email>a[href*="mailto"]')
    If Not @error Then
        ConsoleWrite("! $oSelection_coll.length=" & $oSelection_coll.length & @CRLF)
        For $iSelection_idx = 0 To $oSelection_coll.length -1
            ConsoleWrite($oSelection_coll.item($iSelection_idx).href & @CRLF)
        Next
    EndIf

EndFunc    ;==>_Example



;#FUNCTION#=============================================================================================================
; Name...........: _IEquerySelectorAll()
; Description ...: Returns an Object or a Colection of objects
; Syntax.........: (ByRef $oDoc, $sQuery, $iItemIndex = Default)
; Parameters ....: $oDoc - The document object from IE
;                  $sQuery - String of Query. Example: _IEquerySelectorAll($oDoc, '"div.note, div.alert"', Default) will return a colection of div elements with classes of note and alert
;                  $iItemIndex -     [optional] Default returns a colection, else use a 0 based index to indicate the object in sequence
; Return values .: Success - Object or a Colection of objects
;                  Failure - returns 0 sets the @error flag to non-zero.
;                   3 ($_IEStatus_InvalidDataType) - Invalid Data Type
;                   4 ($_IEStatus_InvalidObjectType) - Invalid Object Type
;                   5 ($_IEStatus_InvalidValue) - Invalid Value
;                   7 ($_IEStatus_NoMatch) - No Match
; Author ........: XThrax aka uncommon
; Remarks .......: This fuction was pretty much stolen from Dale Hohm the IE UDF creator so much credit to him, also to mLipok who made the error checking better.
;                   Also note that this a relatively recent add-on to IE so it requires IE 9 and above.
;                   If you find you receive a com error of "unknown name" its likely the site is using meta tag attribute X-UA-Compatible which has reverted the browser to forget about it.
;
; Related .......: _IETagNameAllGetCollection();_IEClassNameGetCollection()
; Link ..........;https://www.autoitscript.com/forum/topic/181376-_iequeryselectorall/
;                 https://msdn.microsoft.com/en-us/library/cc304115(v=vs.85).aspx
; Example .......; No
; =====================================================================================================================


Func _IEquerySelectorAll(ByRef $oDoc, $sQuery, $iItemIndex = Default)
    If Not IsObj($oDoc) Then
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidDataType & " Invalid DataType" & @LF)
        Return SetError($_IEStatus_InvalidDataType, 1, 0)
    ElseIf Not __IEIsObjType($oDoc, "browserdom") Then
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidObjectType & " Invalid ObjectType" & @LF)
        Return SetError($_IEStatus_InvalidObjectType, 2, 0)
    ElseIf Not IsNumber($iItemIndex) And $iItemIndex <> Default Then
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidValue & " Invalid Index" & @LF)
        Return SetError($_IEStatus_InvalidValue, 3, 0)
    ElseIf $iItemIndex = Default Or $iItemIndex >= 0 Then
        Local $oTemp = Null
        If __IEIsObjType($oDoc, "documentcontainer") Then
            $oTemp = _IEDocGetObj($oDoc)
            If @error Then Return SetError(@error, @extended, 0)
        Else
            $oTemp = $oDoc
        EndIf
        Local $oClassColl = $oTemp.querySelectorAll($sQuery)
        If @error Then
            ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IESTATUS_GeneralError & " GeneralError1: " & @error & @LF)
            Return SetError($_IESTATUS_GeneralError, 3, 0)
        ElseIf (Not IsObj($oClassColl)) Or $oClassColl = Null Or $oClassColl.length = 0 Then
            ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_NoMatch & " NoMatch" & @LF)
            Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both
        Else
            If $iItemIndex = Default Then
                Return SetError($_IEStatus_Success, $oClassColl.length, $oClassColl)
            ElseIf $iItemIndex > $oClassColl.length Then
                ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidValue & " Invalid Value" & @LF)
                Return SetError($_IEStatus_InvalidValue, $oClassColl.length, 0)
            Else
                $oItem = $oClassColl.Item($iItemIndex)
                If @error Then
                    ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IESTATUS_GeneralError & " GeneralError2: " & @error & @LF)
                    Return SetError($_IESTATUS_GeneralError, 3, 0)
                ElseIf (Not IsObj($oItem)) Or $oItem = Null Then
                    ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_NoMatch & " NoMatch Index: " & $iItemIndex & @LF)
                    Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both
                Else
                    Return SetError($_IEStatus_Success, 0, $oItem)
                EndIf
            EndIf
        EndIf
    Else
        ConsoleWriteError("--> _IEquerySelectorAll Error: " & $_IEStatus_InvalidValue & " Invalid Value: " & $iItemIndex & @LF)
        Return SetError($_IEStatus_InvalidValue, 3, 0)
    EndIf
EndFunc   ;==>_IEquerySelectorAll

; User's COM error function.
; After SetUp with ObjEvent("AutoIt.Error", ....) will be called if COM error occurs
Func _User_ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_User_ErrFunc

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites

Hi :)

Try:

Func f_MyFunc()
    $oIE = _IECreate("YOUR_URL.aspx", 0, 0, 1, 0) ;accord with your needs
    _IELoadWait($oIE)
    _IEQuit ( $oIE )
    $sRead = InetRead('YOUR_URL.aspx');accord with your needs
    $aLinksEmail = _StringBetween($aDataBIOS[0], '<div><a>', '</a></div>')
    $slinksEmail = ""
    For $i = 0 To UBound($aLinksEMAIL) - 1
        If StringInStr($aLinksEMAIL[$i], "email") Then
            $a2LinksEmail = _StringBetween($aLinksEMAIL[$i], '<a href="/', '"></a')
            $sLinksEmail = $a2LinksEMAIL[0]
            ExitLoop
        EndIf
    Next
    Msgbox(0, "email", $a2LinksEMAIL[0])
EndFunc

Don't forget #include <IE.au3> at the beginning.

Hope that helps :)

-31290-


~~~ Doom Shall Never Die, Only The Players ~~~

Share this post


Link to post
Share on other sites
2 hours ago, nirmalsalem said:

Actually I need to read the email id rather than writing to the webpage.

Your was asking about Reading not Writing.
So did you try this my example to make what you need ?

btw.

Your HTML Snippet does not contain any "TAG" which should be editabled by EndUser.
So how user should fill up this HTML FORM ?

 

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By learner123
      Hi All,
       
      I am new to this AUTO IT and I have created a script that will open an app,enter pin and copy the code generated to clipboard. My java code call this autoIT script and use the copied generated code from clipboard.
      This works fine when server  window is on focus. My server is an windows server. 
      But when I minimize or disconnect the server, the script opens the app.exe but doesn't copy any value to clipboard.  
      Can anyone help me on this 😐
       
      Run("C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe")
      Local $hWnd=WinWait("abc - RSA SecurID Token") ; waits until the window is the active window
      $hWin = WinGetHandle("abc - RSA SecurID Token");
      ControlSend($hWnd,"","","1111") ; simulates pressing the Home key
      ControlSend($hWnd,"","","{ENTER}");
      ControlSend($hWnd,"","","^c");
      Sleep(1000) ;
      ControlSend($hWnd,"","","^c");
       
    • By learner123
      Hi All,
      So I have created a small autoIT script to enter pin into a RSA token(app which generate new code every 30 second), and copy the generated code.
      I have a java application which requires this code so every time my java-code requires this RSA code, it runs the autoIT script and the copied generated code is then used in my java application. 
      I have deployed this code on a windows server and it works fine when I am logged in and the window is on focus, But as soon as I schedule task and disconnect the server (not logged out only disconnect), or even minimize the server window, the autoIT scripts fails and its not able to copy the value.
       
      Please find below the code for AUTOIT.
       
      WinActivate("rsa - RSA SecurID Token") ; activates the window that has old in the tilte bar
      WinWaitActive("rsa - RSA SecurID Token") ; waits until the window is the active window
      Send("1111") ; simulates pressing the Home key, enters password to get the code
      Send("{ENTER}") ; simulates pressing the Enter key
      Sleep(1000) ;
      Send("^c") ; simulates pressing the CTRL+c keys (copy)
       
      Also I saw some post regarding that WINACTIVE only works when window is active. But my below AUTO IT script to handle windows pop up  works perfectly fine when the server is disconnected. 
       
      Opt("WinTitleMatchMode", 1)
      WinWait("https://url","","10")
      WinWaitActive("https://url","","10")
      Sleep(2000)
      Send("userid")
      Sleep(1000)
      Send("{TAB}")
      Sleep(1000)
      Send("passwrd")
      Send("{TAB}")
      Sleep(500)
      Send("{ENTER}")
       
       
    • By JuanFelipe
      Hello gyus, I try to make a code to login in a web page in my job, buy i can’t understand why my form is blocked, this is my code: 
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <StringConstants.au3> #include <WindowsConstants.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <Array.au3> #include <IE.au3> #include <Excel.au3> #include <GuiEdit.au3> #include <GuiStatusBar.au3> #include <DateTimeConstants.au3> #include <Date.au3> #Region ### START Koda GUI section ### Form=C:\noentry\koda_1.7.3.0\Forms\spoa.kxf $Form1 = GUICreate("Eva y Vehículos", 1200, 1000, 10, 10) $prueba = GUICtrlCreateButton("Prueba",10,990,50,20) ;VARIABLES ========================================================================================== $psi = "https://psi.policia.gov.co/PSI/Login.aspx?ReturnUrl=%2fPSI#no-back-button" $chequeVehiculos = "https://psi.policia.gov.co/PSI/frm_lista_chk.aspx" $evaluacionEva = "https://psi.policia.gov.co/PSI/eva_frmver.aspx" $oIE = ObjCreate("Shell.Explorer.2") $GUIActiveX = GUICtrlCreateObj ($oIE, 10, 10, 1180, 980) ;GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) $oIE.navigate($psi) ;_IELoadWait($oIE) _InicioSesion() #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $prueba _InicioSesion() EndSwitch WEnd Func _InicioSesion() Local $username = _IEGetObjByName($oIE, "txtUsuario") Local $pass = _IEGetObjByName($oIE, "txtClave") Local $logina = _IEGetObjByName($oIE, "btnIngresar") $username.value="example" $pass.value="examplepass" _IEAction($logina, 'click') _IELoadWait($oIE) MsgBox(16,"","") EndFunc  
    • By shelly
      Here is the below code for handling pop-up when window is  inactive ..but I don't know how to change sleep and when i run this script it runs sometimes and sometimes it stops .
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{SPACE}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{DOWN}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{ENTER}")
      --- these 3 lines never worked while TAB lines works sometimes but not in accurate way
      I am new too AutoIt .. help me out why this script behaves in strange way
      ControlFocus("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog", "", "Internet Explorer_Server1","1")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog", "", "Internet Explorer_Server1","the request is send")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{SPACE}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{DOWN}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      Sleep(3000)
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{TAB}")
      ControlSend("Policy Decisions -- Webpage Dialog","","Internet Explorer_Server1","{ENTER}")
       
×
×
  • Create New...