Jump to content

How can i take a text that is generate dynamicaly from javascript?


Recommended Posts

Hello,

how can i take the text: "Total Price: 33.54 GBP" and "Total Price: 25.00 GBP"

this text is generate dynamicaly from javascript.

#include <IE.au3>
#include <Array.au3>

$oIE = _IECreate ("http://www.ryanair.com/php/sbforms/form.php")
$SBform = _IEFormGetCollection ($oIE,0)

;Departing from:
$o = _IEFormElementGetObjByName ($SBform,"sector1_o")
_IEFormElementOptionselect ($o, "London-Gatwick (LGW)", 1, "byText")

;Going to:
$d = _IEFormElementGetObjByName ($SBform,"sector1_d")
_IEFormElementOptionselect ($d, "Cork (ORK)", 1, "byText")

;Depart date:
$gA = _IEFormElementGetObjByName ($SBform,"sector_1_d")
_IEFormElementOptionselect ($gA, "01", 1, "byText")
$mA = _IEFormElementGetObjByName ($SBform,"sector_1_m")
_IEFormElementOptionselect ($mA, "Jun 2009", 1, "byText")

;Return Date:
$gR = _IEFormElementGetObjByName ($SBform,"sector_2_d")
_IEFormElementOptionselect ($gR, "03", 1, "byText")
$mR = _IEFormElementGetObjByName ($SBform,"sector_2_m")
_IEFormElementOptionselect ($mR, "Jun 2009", 1, "byText")

_IEFormSubmit ($SBform,0)
_IELoadWait ($oIE,Random(10000,20000,1))

_IEQuit ($oIE)
Exit

thanks bye

Link to comment
Share on other sites

Someone probably has a better way but this works.

-Kenny

#include <IE.au3>
#include <Array.au3>

$oIE = _IECreate ("http://www.ryanair.com/php/sbforms/form.php")
$SBform = _IEFormGetCollection ($oIE,0)

;Departing from:
$o = _IEFormElementGetObjByName ($SBform,"sector1_o")
_IEFormElementOptionselect ($o, "London-Gatwick (LGW)", 1, "byText")

;Going to:
$d = _IEFormElementGetObjByName ($SBform,"sector1_d")
_IEFormElementOptionselect ($d, "Cork (ORK)", 1, "byText")

;Depart date:
$gA = _IEFormElementGetObjByName ($SBform,"sector_1_d")
_IEFormElementOptionselect ($gA, "01", 1, "byText")
$mA = _IEFormElementGetObjByName ($SBform,"sector_1_m")
_IEFormElementOptionselect ($mA, "Jun 2009", 1, "byText")

;Return Date:
$gR = _IEFormElementGetObjByName ($SBform,"sector_2_d")
_IEFormElementOptionselect ($gR, "03", 1, "byText")
$mR = _IEFormElementGetObjByName ($SBform,"sector_2_m")
_IEFormElementOptionselect ($mR, "Jun 2009", 1, "byText")

_IEFormSubmit ($SBform,0)
_IELoadWait ($oIE,Random(2000,20000,1))

$html = _IEBodyReadText($oIE)
$html = StringTrimLeft($html, StringInStr($html, "Taxes / Fees:") + 14)
$Taxes = StringStripCR( StringLeft($html, StringInStr($html, "GBP") + 3 ) )
$html = StringTrimLeft($html, StringInStr($html, "Total Price:") + 12)
$Total = StringStripCR( StringLeft($html, StringInStr($html, "GBP") + 3) )
MsgBox(0,"",$Taxes & @CR & $Total)

Exit

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

And here's that better way. :)

#include <IE.au3>
#include <Array.au3>

$oIE = _IECreate ("http://www.ryanair.com/php/sbforms/form.php")
$SBform = _IEFormGetCollection ($oIE,0)

;Departing from:
$o = _IEFormElementGetObjByName ($SBform,"sector1_o")
_IEFormElementOptionselect ($o, "London-Gatwick (LGW)", 1, "byText")

;Going to:
$d = _IEFormElementGetObjByName ($SBform,"sector1_d")
_IEFormElementOptionselect ($d, "Cork (ORK)", 1, "byText")

;Depart date:
$gA = _IEFormElementGetObjByName ($SBform,"sector_1_d")
_IEFormElementOptionselect ($gA, "01", 1, "byText")
$mA = _IEFormElementGetObjByName ($SBform,"sector_1_m")
_IEFormElementOptionselect ($mA, "Jun 2009", 1, "byText")

;Return Date:
$gR = _IEFormElementGetObjByName ($SBform,"sector_2_d")
_IEFormElementOptionselect ($gR, "03", 1, "byText")
$mR = _IEFormElementGetObjByName ($SBform,"sector_2_m")
_IEFormElementOptionselect ($mR, "Jun 2009", 1, "byText")

_IEFormSubmit ($SBform,0)
_IELoadWait ($oIE,Random(10000,20000,1))

; This will loop through all of the tables on the page so you can see which one you need
$oTable = _IETableGetCollection ($oIE)
$iNumTables = @extended
For $x = 0 to $iNumTables
    ; Once you know which table #, you can just use the following two lines
    $oTable = _IETableGetCollection ($oIE, $x)
    $array = _IETableWriteToArray ($oTable)
    _ArrayDisplay ($array, "Table Number: " & $x)
Next
Edited by exodius
Link to comment
Share on other sites

Knew it wouldn't take long for someone to do a better job than me lol :)

When I did a view source in IE a search couldn't find that section that's why I went the text route.

__________

I just got my Irish passport did we earn a discount on airfare now? lol

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

THANK YOU!! :)

I used to have that thing or something similar at least. But couldn't remember the name after my last format and I couldn't remember the name to re-install :party:

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

And here's that better way. :)

#include <IE.au3>
#include <Array.au3>

$oIE = _IECreate ("http://www.ryanair.com/php/sbforms/form.php")
$SBform = _IEFormGetCollection ($oIE,0)

;Departing from:
$o = _IEFormElementGetObjByName ($SBform,"sector1_o")
_IEFormElementOptionselect ($o, "London-Gatwick (LGW)", 1, "byText")

;Going to:
$d = _IEFormElementGetObjByName ($SBform,"sector1_d")
_IEFormElementOptionselect ($d, "Cork (ORK)", 1, "byText")

;Depart date:
$gA = _IEFormElementGetObjByName ($SBform,"sector_1_d")
_IEFormElementOptionselect ($gA, "01", 1, "byText")
$mA = _IEFormElementGetObjByName ($SBform,"sector_1_m")
_IEFormElementOptionselect ($mA, "Jun 2009", 1, "byText")

;Return Date:
$gR = _IEFormElementGetObjByName ($SBform,"sector_2_d")
_IEFormElementOptionselect ($gR, "03", 1, "byText")
$mR = _IEFormElementGetObjByName ($SBform,"sector_2_m")
_IEFormElementOptionselect ($mR, "Jun 2009", 1, "byText")

_IEFormSubmit ($SBform,0)
_IELoadWait ($oIE,Random(10000,20000,1))

; This will loop through all of the tables on the page so you can see which one you need
$oTable = _IETableGetCollection ($oIE)
$iNumTables = @extended
For $x = 0 to $iNumTables
    ; Once you know which table #, you can just use the following two lines
    $oTable = _IETableGetCollection ($oIE, $x)
    $array = _IETableWriteToArray ($oTable)
    _ArrayDisplay ($array, "Table Number: " & $x)
Next
Perfect!! good solution,

But the tables are generated dynamically and the number of tables varies depending on whether there is or there is not flight for that day.

4 table -> means: (no flight on this day )

5 table -> means: (there is an "outward flight" or an "return flight" and the radio button is not selected)

6 table -> means: (there is an "outward flight" or an "return flight" and the radio button is selected)

8 table -> means: (there is an "outward flight" and an "return flight")

How to handle these cases? Perhaps by interacting directly with the javascript?

If there are more flights on the same day (as for London-Paris) how do i select

the radio butto to select all the flights and take all prices?

Thanks bye!

Link to comment
Share on other sites

  • Moderators

Have fun!

#include <IE.au3>
#include <Array.au3>

_IEErrorHandlerRegister()
$oIE = _IECreate("http://www.ryanair.com/php/sbforms/form.php")
$SBform = _IEFormGetCollection($oIE, 0)

;Departing from:
$o = _IEFormElementGetObjByName($SBform, "sector1_o")
_IEFormElementOptionselect($o, "Paris-Beauvais (BVA)", 1, "byText")

;Going to:
$d = _IEFormElementGetObjByName($SBform, "sector1_d")
_IEFormElementOptionselect($d, "Rome (Ciampino) (CIA)", 1, "byText")

;Depart date:
$gA = _IEFormElementGetObjByName($SBform, "sector_1_d")
_IEFormElementOptionselect($gA, "01", 1, "byText")
$mA = _IEFormElementGetObjByName($SBform, "sector_1_m")
_IEFormElementOptionselect($mA, "Jun 2009", 1, "byText")

;Return Date:
$gR = _IEFormElementGetObjByName($SBform, "sector_2_d")
_IEFormElementOptionselect($gR, "30", 1, "byText")
$mR = _IEFormElementGetObjByName($SBform, "sector_2_m")
_IEFormElementOptionselect($mR, "Jun 2009", 1, "byText")

_IEFormSubmit($SBform, 0)
_IELoadWait($oIE)

$oForm = _IEFormGetCollection($oIE, 0)
$oRadioCollection1 = _IEFormElementGetObjByName($oForm, "AvailabilityInputFRSelectView$market1", -1)
$oRadioCollection2 = _IEFormElementGetObjByName($oForm, "AvailabilityInputFRSelectView$market2", -1)

If Not IsObj($oRadioCollection1) And Not IsObj($oRadioCollection2) Then Exit

If IsObj($oRadioCollection1) Then
    If ObjName($oRadioCollection1) = "DispHTMLInputElement" Then
        $iFlights1 = 1
    Else
        $iFlights1 = $oRadioCollection1.length
    EndIf
Else
    $iFlights1 = 0
EndIf

If IsObj($oRadioCollection2) Then
    If ObjName($oRadioCollection2) = "DispHTMLInputElement" Then
        $iFlights2 = 1
    Else
        $iFlights2 = $oRadioCollection2.length
    EndIf
Else
    $iFlights2 = 0
EndIf

For $i = 0 To $iFlights1 - 1
    $oRadio1 = _IEFormElementRadioSelect($oForm, $i, "AvailabilityInputFRSelectView$market1", 1, "byIndex")
    $aTableBody1 = _GetTableInfoById("taxAndFeeInclusiveDivBody1")
    _ArrayDisplay($aTableBody1, "Going Out Flight #" & $i + 1)
Next

For $i = 0 To $iFlights2 - 1
    $oRadio2 = _IEFormElementRadioSelect($oForm, $i, "AvailabilityInputFRSelectView$market2", 1, "byIndex")
    $aTableBody2 = _GetTableInfoById("taxAndFeeInclusiveDivBody2")
    _ArrayDisplay($aTableBody2, "Coming Back Flight #" & $i + 1)
Next

Func _GetTableInfoById($sId)
    $oDivBody = _IEGetObjById($oIE, $sId)
    While StringInStr($oDivBody.innerText, "Please Wait")
        Sleep(50)
    WEnd
    $oTableBody = _IETagNameGetCollection($oDivBody, "table", 0)
    $aTableBody = _IETableWriteToArray($oTableBody, True)
    Return $aTableBody
EndFunc   ;==>_GetTableInfoById
Link to comment
Share on other sites

Have fun!

#include <IE.au3>
#include <Array.au3>

_IEErrorHandlerRegister()
$oIE = _IECreate("http://www.ryanair.com/php/sbforms/form.php")
$SBform = _IEFormGetCollection($oIE, 0)

;Departing from:
$o = _IEFormElementGetObjByName($SBform, "sector1_o")
_IEFormElementOptionselect($o, "Paris-Beauvais (BVA)", 1, "byText")

;Going to:
$d = _IEFormElementGetObjByName($SBform, "sector1_d")
_IEFormElementOptionselect($d, "Rome (Ciampino) (CIA)", 1, "byText")

;Depart date:
$gA = _IEFormElementGetObjByName($SBform, "sector_1_d")
_IEFormElementOptionselect($gA, "01", 1, "byText")
$mA = _IEFormElementGetObjByName($SBform, "sector_1_m")
_IEFormElementOptionselect($mA, "Jun 2009", 1, "byText")

;Return Date:
$gR = _IEFormElementGetObjByName($SBform, "sector_2_d")
_IEFormElementOptionselect($gR, "30", 1, "byText")
$mR = _IEFormElementGetObjByName($SBform, "sector_2_m")
_IEFormElementOptionselect($mR, "Jun 2009", 1, "byText")

_IEFormSubmit($SBform, 0)
_IELoadWait($oIE)

$oForm = _IEFormGetCollection($oIE, 0)
$oRadioCollection1 = _IEFormElementGetObjByName($oForm, "AvailabilityInputFRSelectView$market1", -1)
$oRadioCollection2 = _IEFormElementGetObjByName($oForm, "AvailabilityInputFRSelectView$market2", -1)

If Not IsObj($oRadioCollection1) And Not IsObj($oRadioCollection2) Then Exit

If IsObj($oRadioCollection1) Then
    If ObjName($oRadioCollection1) = "DispHTMLInputElement" Then
        $iFlights1 = 1
    Else
        $iFlights1 = $oRadioCollection1.length
    EndIf
Else
    $iFlights1 = 0
EndIf

If IsObj($oRadioCollection2) Then
    If ObjName($oRadioCollection2) = "DispHTMLInputElement" Then
        $iFlights2 = 1
    Else
        $iFlights2 = $oRadioCollection2.length
    EndIf
Else
    $iFlights2 = 0
EndIf

For $i = 0 To $iFlights1 - 1
    $oRadio1 = _IEFormElementRadioSelect($oForm, $i, "AvailabilityInputFRSelectView$market1", 1, "byIndex")
    $aTableBody1 = _GetTableInfoById("taxAndFeeInclusiveDivBody1")
    _ArrayDisplay($aTableBody1, "Going Out Flight #" & $i + 1)
Next

For $i = 0 To $iFlights2 - 1
    $oRadio2 = _IEFormElementRadioSelect($oForm, $i, "AvailabilityInputFRSelectView$market2", 1, "byIndex")
    $aTableBody2 = _GetTableInfoById("taxAndFeeInclusiveDivBody2")
    _ArrayDisplay($aTableBody2, "Coming Back Flight #" & $i + 1)
Next

Func _GetTableInfoById($sId)
    $oDivBody = _IEGetObjById($oIE, $sId)
    While StringInStr($oDivBody.innerText, "Please Wait")
        Sleep(50)
    WEnd
    $oTableBody = _IETagNameGetCollection($oDivBody, "table", 0)
    $aTableBody = _IETableWriteToArray($oTableBody, True)
    Return $aTableBody
EndFunc   ;==>_GetTableInfoById
thanks so much!!! :)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...