Jump to content
Valnurat

"collect" data inside the <tr> </tr> tags

Recommended Posts

Yes, of course.

I do would like to know how I can catch how many seats there's for each trip.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <Constants.au3>
#include <IE.au3>

Local $sOrigin = "CPH", $sDest = "EWR", $sDepart = "20210117", $iAdult = 2
Local $sURL = "https://www.sas.dk/book/flights?search=OW_" & $sOrigin & "-" & $sDest & "-" & $sDepart & "_a" & $iAdult & _
    "c0i0y0&view=upsell&bookingFlow=points&sortBy=stop&filterBy=all"
Local $oIE = _IECreate($sURL), $oWarn, $oTable, $oTableTrs, $oOffers, $oTrs, $oTags, $oSpans
For $i = 1 To 30
  Sleep(100)
  $oWarn = _IEGetObjById ($oIE,"got-it")
  If Not @error Then ExitLoop
Next
If Not IsObj($oWarn) Then Exit ConsoleWrite("Unable to get warning screen")
$oWarn.click()
;_IELoadWait($oIE)
Sleep(5000)
$oOffers = _IETagNameGetCollection($oIE, "offers")
For $oOffer In $oOffers
    $oTrs = _IETagNameGetCollection($oOffer, "tr")
    For $oTr In $oTrs
        If $oTr.className = 'product-column-wrap' and $oTr.id <> '' Then
            $oTable = _GetObj($oIE, $oTr.id, 2000)
            If Not IsObj($oTable) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Unable to get price table")
            $oTags = _IETagNameGetCollection($oTable,"p")
            For $oTag in $oTags
                If $oTag.innerText = "48 000" Then
                    $oSpans = _IETagNameGetCollection($oTable,"span")
                    For $oSpan In $oSpans
                        ConsoleWrite ($oSpan.className & @CRLF)
                    Next
                EndIf
            Next
        EndIf
    Next
Next

Func _GetObj (ByRef $oIE, $sStr, $iTime)
  Local $oObj
  For $i = 1 To Int($iTime/100)
    Sleep(100)
    $oObj = _IEGetObjById ($oIE, $sStr)
    If Not @error Then Return $oObj
  Next
  Return SetError(1, 0, 0)
EndFunc

For some reason the _IELoadWait($oIE) dos not work, so I use the sleep function.

ConsoleWrite ($oSpan.className & @CRLF) I use for see what I get, but I don't get anything.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Maybe this will help you towards your goal --

#include <IE.au3>

Local $sOrigin = "CPH", $sDest = "EWR", $sDepart = "20210117", $iAdult = 2
Local $sURL = "https://www.sas.dk/book/flights?search=OW_" & $sOrigin & "-" & $sDest & "-" & $sDepart & "_a" & $iAdult & _
    "c0i0y0&view=upsell&bookingFlow=points&sortBy=stop&filterBy=all"

Local $oIE = _IECreate($sURL), $oWarn

For $i = 1 To 30
  Sleep(100)
  $oWarn = _IEGetObjById ($oIE,"got-it")
  If Not @error Then ExitLoop
Next
If Not IsObj($oWarn) Then Exit ConsoleWrite("Unable to get warning screen")
$oWarn.click()
Sleep(5000)

$oOffers = _IETagNameGetCollection($oIE, "offers")

For $oOffer In $oOffers
    ConsoleWrite($oOffer.firstChild.id & @crlf)

    $oTDs = _IETagNameGetCollection($oOffer, "TD")

    For $oTD IN $oTDs
        If StringInStr($oTD.className, "slide") Then
            ConsoleWrite($oTD.innerText & @CRLF)
        EndIf
    Next
Next

 

Share this post


Link to post
Share on other sites
On 11/16/2020 at 11:32 PM, Danp2 said:

Maybe this will help you towards your goal --

#include <IE.au3>

Local $sOrigin = "CPH", $sDest = "EWR", $sDepart = "20210117", $iAdult = 2
Local $sURL = "https://www.sas.dk/book/flights?search=OW_" & $sOrigin & "-" & $sDest & "-" & $sDepart & "_a" & $iAdult & _
    "c0i0y0&view=upsell&bookingFlow=points&sortBy=stop&filterBy=all"

Local $oIE = _IECreate($sURL), $oWarn

For $i = 1 To 30
  Sleep(100)
  $oWarn = _IEGetObjById ($oIE,"got-it")
  If Not @error Then ExitLoop
Next
If Not IsObj($oWarn) Then Exit ConsoleWrite("Unable to get warning screen")
$oWarn.click()
Sleep(5000)

$oOffers = _IETagNameGetCollection($oIE, "offers")

For $oOffer In $oOffers
    ConsoleWrite($oOffer.firstChild.id & @crlf)

    $oTDs = _IETagNameGetCollection($oOffer, "TD")

    For $oTD IN $oTDs
        If StringInStr($oTD.className, "slide") Then
            ConsoleWrite($oTD.innerText & @CRLF)
        EndIf
    Next
Next

 

Yes, that did it. I can use this. Thank you.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

No, but maybe something from the examples was useful, but thank you for the link. I will look into it. 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Holy crap. 😲

#include "WinHttp.au3"

$sAddress = "https://api.pushover.net/1/messages.json"

$sApiToken = "av26ac2nAXLyPKg2QMy4zf9YcUjz2G" ; <-yours here
$sUserKey = "uMQf396GvMgrsDroaryKEvVyWkgfkw" ; <-yours here
$sMessage = "hello world"

; Construct the form
Const $sForm = '<form action="' & $sAddress & '" method="post">' & _
'<input name="token" value="' & $sApiToken & '"/>' & _
'<input name="user" value="' & $sUserKey & '"/>' & _
'<input name="message" value="' & $sMessage & '"/>' & _
'</form>'

; Open session
$hOpen = _WinHttpOpen()
; To collect connection handle (because the form is inlined)
$hConnect = $sForm

; Fill the form
$sRead = _WinHttpSimpleFormFill($hConnect, $hOpen)

; Close handles
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

; Tada mtfk!
MsgBox(4096, "Simon says", $sRead)

This worked.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

I'm trying to stop the for..next loop when I press the stop button, but how can it be done?

What I already did dos not do any good.  I hope you can help me. 🙂

#include <Array.au3>
#include <IE.au3>
#include "WinHttp.au3"
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
                    ,["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
                    ,["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:",10,10)
$idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) -1
    $sFill &= $aBase[$i][0] & "|" ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:",10,52)
$idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) -1
    $sFill &= $aBase[$i][0] & "|" ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:",10,95)
Local $idDate = GUICtrlCreateDate("" ,10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

$idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun",10,180)
GUICtrlCreateInput("45", 10, 230, 30, 20)
Local $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
    _Fill_List()
EndIf

$state = 0
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Local $sFill = ""
            For $i = 0 to _GUICtrlListBox_GetCount($idMylist) -1
                $sFill &= _GUICtrlListBox_GetText($idMylist,$i) & "|"
            Next
            $sFill = StringTrimRight($sFill, 1)
            _ArrayAdd($aTmpRejser, $sFill)
            _FileWriteFromArray($Rejserspath, $aTmpRejser)
            ExitLoop
        Case $idButton_AddTrip
            $sOrigin = GUICtrlRead($idComboFra)
            $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
            $sDest = GUICtrlRead($idComboTil)
            $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
            _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
;       Case $idButton_Clear
;           GUICtrlSetData($idMylist, "")
        Case $idButton_Run
            If $state Then
                $state = 0
                GUICtrlSetData($idButton_Run, "Start")
                ExitLoop
            Else
               $state = 1
                GUICtrlSetData($idButton_Run, "Stop")
                For $i = 0 to _GUICtrlListBox_GetCount($idMylist) -1
                    $RDMSleep = Random(5,9,1)
                    $RDMSleep = $RDMSleep & '000'
                    Sleep($RDMSleep)
                    ConsoleWrite(_GUICtrlListBox_GetText($idMylist,$i) & @CRLF)
                Next
            EndIf
    EndSwitch
WEnd

Func _Fill_List()
    ; Read the file into an array
    Local $array
    _FileReadToArray($rejserspath, $array)
    ; Check we read something
    If IsArray($array) Then
        ; Convert to a string with delimiters
        $sList = ""
        For $i = 1 To $array[0]
            $sList &= "|" & $array[$i]
        Next
        ; And fill the list
        GUICtrlSetData($idMylist, $sList)
    EndIf

EndFunc

 

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

@Danp2 Yes, it is true in the $idButton_Run.

If that can't be done, how can I add a timer that re-run my for..next loop after 45 min with the option to break the timer instead of closing the application?

Edited by Valnurat

Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

@Valnurat You can get time right before entering for-next and get time again each iteration of the loop, and do an if check for elapsed time.

Another option might be adding a msgbox that appears every n iterations for a brief moment, ie, a couple of seconds. You should be able to achieve this by putting the msgbox inside an if statement which checks for (mathematical function) "mod ($i, n) = 0". You will have to figure out what would be approriate for n. Also, don't forget to put a timeout value for msgbox.

MOD Function

MsgBox ( flag, "title", "text" [, timeout = 0 [, hwnd]] )

Share this post


Link to post
Share on other sites

I see. Then it is quite easy to extract the For loop from the Case statement and integrate a pseudo-loop outside the Switch statement.  Something along those lines :

#include <Array.au3>
#include <IE.au3>
;#include "WinHttp.au3"
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
    , ["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
    , ["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:", 10, 10)
$idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:", 10, 52)
$idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:", 10, 95)
Local $idDate = GUICtrlCreateDate("", 10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

$idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun", 10, 180)
GUICtrlCreateInput("45", 10, 230, 30, 20)
Local $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
  _Fill_List()
EndIf

Local $state = 0, $indx

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Local $sFill = ""
      For $i = 0 To _GUICtrlListBox_GetCount($idMylist) - 1
        $sFill &= _GUICtrlListBox_GetText($idMylist, $i) & "|"
      Next
      $sFill = StringTrimRight($sFill, 1)
      _ArrayAdd($aTmpRejser, $sFill)
      _FileWriteFromArray($Rejserspath, $aTmpRejser)
      ExitLoop
    Case $idButton_AddTrip
      $sOrigin = GUICtrlRead($idComboFra)
      $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
      $sDest = GUICtrlRead($idComboTil)
      $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
      _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
      ;       Case $idButton_Clear
      ;           GUICtrlSetData($idMylist, "")
    Case $idButton_Run
      If $state Then
        $state = 0
        GUICtrlSetData($idButton_Run, "Start")
        ;ExitLoop
      Else
        $state = 1
        $indx = 0
        GUICtrlSetData($idButton_Run, "Stop")
      EndIf
  EndSwitch
  If $state Then
    ;ConsoleWrite ("started" & @CRLF)
    If $indx < _GUICtrlListBox_GetCount($idMylist) Then
      $RDMSleep = Random(5, 9, 1)
      $RDMSleep = $RDMSleep * 1000
      Sleep($RDMSleep)
      ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
      $indx += 1
    Else
      $state = 0
      GUICtrlSetData($idButton_Run, "Start")
    EndIf
  EndIf

WEnd

Func _Fill_List()
  ; Read the file into an array
  Local $array
  _FileReadToArray($Rejserspath, $array)
  ; Check we read something
  If IsArray($array) Then
    ; Convert to a string with delimiters
    $sList = ""
    For $i = 1 To $array[0]
      $sList &= "|" & $array[$i]
    Next
    ; And fill the list
    GUICtrlSetData($idMylist, $sList)
  EndIf

EndFunc   ;==>_Fill_List

But beware of the Sleep.  It will force you to wait till it is completed, unless...

Edited by Nine

Share this post


Link to post
Share on other sites

Thank you, but it does not stop the for..next loop when I press the "stop" button. It just go through all lines in my list and then stop and change the name to "Start" and then I need to press the "Start" button again to do another run. I was hoping it could do a new run after 45 min. for an example, but I would like to press the "stop" button no matter where in the for..next loop or in the next new run, but if it can't break the for..next while it is running, then maybe it could break in the timer.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Yes, your code does as I described.

I can't stop it. If I press the stop button, while it is in progress, it thinks I pressed the start button again and go through the list 1 more time.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

It is because of the Sleep.  If you click when it is on Sleep, the click is not registered.

Share this post


Link to post
Share on other sites

Here one way how to remove the Sleep and make it work :

#include <Array.au3>
#include <IE.au3>
;#include "WinHttp.au3"
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <File.au3>

Local $aBase[15][2] = [["Copenhagen", "CPH"], ["Beijing", "PEK"], ["Boston", "BOS"], ["Chicago", "ORD"], ["Hong Kong", "HKG"], ["Los Angeles", "LAX"] _
    , ["Miami", "MIA"], ["Manila", "MNL"], ["New Jersey", "EWR"], ["Oslo", "OSL"], ["San Francisco", "SFO"], ["Shanghai", "PVG"], ["Stockholm", "ARN"] _
    , ["Tokyo", "NRK"], ["Washington", "IAD"]], $sFill, $aTmpRejser[0]
;_ArrayDisplay($aTmpRejser)
Global $Rejserspath = "Rejser.txt"

; Create GUI
GUICreate("MyProject", 400, 296)

GUICtrlCreateLabel("Fra:", 10, 10)
$idComboFra = GUICtrlCreateCombo("", 10, 25, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboFra, $sFill, "Copenhagen")

$sFill = ""
GUICtrlCreateLabel("Til:", 10, 52)
$idComboTil = GUICtrlCreateCombo("", 10, 68, 106, 25)
For $i = 0 To UBound($aBase) - 1
  $sFill &= $aBase[$i][0] & "|"   ; Note variables added as number datatype here
Next
$sFill = StringTrimRight($sFill, 1)
GUICtrlSetData($idComboTil, $sFill, "Copenhagen")

GUICtrlCreateLabel("Dato:", 10, 95)
Local $idDate = GUICtrlCreateDate("", 10, 110, 106, Default, $DTS_SHORTDATEFORMAT)

$idMylist = GUICtrlCreateList("", 122, 10, 270, 170)

Local $idButton_AddTrip = GUICtrlCreateButton("Add Trip", 10, 145, 105, 25)
Local $idButton_Delete = GUICtrlCreateButton("Delete From List", 140, 180, 105, 25)
Local $idButton_Mark = GUICtrlCreateButton("Marker", 270, 180, 105, 25)

GUICtrlCreateLabel("Time to rerun", 10, 180)
GUICtrlCreateInput("45", 10, 230, 30, 20)
Local $idButton_Run = GUICtrlCreateButton("Start", 10, 260, 105, 25)

GUISetState(@SW_SHOW)

If FileExists($Rejserspath) Then
  _Fill_List()
EndIf

Local $state, $indx, $cal

While 1
  Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
      Local $sFill = ""
      For $i = 0 To _GUICtrlListBox_GetCount($idMylist) - 1
        $sFill &= _GUICtrlListBox_GetText($idMylist, $i) & "|"
      Next
      $sFill = StringTrimRight($sFill, 1)
      _ArrayAdd($aTmpRejser, $sFill)
      _FileWriteFromArray($Rejserspath, $aTmpRejser)
      ExitLoop
    Case $idButton_AddTrip
      $sOrigin = GUICtrlRead($idComboFra)
      $sOrigin = $aBase[_ArraySearch($aBase, $sOrigin, 0, 0, 0, 1, 1, 0)][1]
      $sDest = GUICtrlRead($idComboTil)
      $sDest = $aBase[_ArraySearch($aBase, $sDest, 0, 0, 0, 1, 1, 0)][1]
      _GUICtrlListBox_AddString($idMylist, "Fra: " & $sOrigin & " Til: " & $sDest & " Antal: 2" & " Afr: " & (GUICtrlRead($idDate) & " Ikke fundet"))
      ;       Case $idButton_Clear
      ;           GUICtrlSetData($idMylist, "")
    Case $idButton_Run
      If $state Then
        $state = 0
        GUICtrlSetData($idButton_Run, "Start")
      Else
        $state = 1
        $indx = 0
        $cal = 0
        GUICtrlSetData($idButton_Run, "Stop")
      EndIf
  EndSwitch
  If $state Then
    If $indx < _GUICtrlListBox_GetCount($idMylist) Then
      If Not $cal Then
        $RDMSleep = Random(2, 4, 1) * 1000
        $hTimer = TimerInit()
        $cal = 1
      ElseIf TimerDiff($hTimer) > $RDMSleep Then
        ConsoleWrite(_GUICtrlListBox_GetText($idMylist, $indx) & @CRLF)
        $indx += 1
        $cal = 0
      EndIf
    Else
      $state = 0
      GUICtrlSetData($idButton_Run, "Start")
    EndIf
  EndIf

WEnd

Func _Fill_List()
  ; Read the file into an array
  Local $array
  _FileReadToArray($Rejserspath, $array)
  ; Check we read something
  If IsArray($array) Then
    ; Convert to a string with delimiters
    $sList = ""
    For $i = 1 To $array[0]
      $sList &= "|" & $array[$i]
    Next
    ; And fill the list
    GUICtrlSetData($idMylist, $sList)
  EndIf

EndFunc   ;==>_Fill_List

 

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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...