Jump to content
Valnurat

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

Recommended Posts

My goal is to search for either 30000, 48000 or 60000. If there's a match I need to see how many seat left.

I thought it was in some kind of table, but when I try the code, I'm not getting the data I'm searching for.

I hope someone can help me with this. Any kind of help will be helpful

#include <Constants.au3>
#include <IE.au3>
#include <Array.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()
Local $oTable = _IETableGetCollection($oIE,0)
Local $aTableData = _IETableWriteToArray($oTable)
_ArrayDisplay($aTableData)
ConsoleWrite("Done" & @CRLF)

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Not sure why you chose to start a new thread when this is clearly a continuation of the prior one. You also haven't given us enough information to be able to know what you are wanting to accomplish. ūüôĄ

You said "30000, 48000 or 60000", but I suspect that you meant "36000, 48000 or 60000", which are the prices shown. My suggestion is to use the Developer Tools in either Chrome or Firefox to help identify the element that you want to access. By doing this, you would see that the table has an ID of "outbound-upsell-table". Something like this should work --

$oTable = _IEGetObjById ($oIE,"outbound-upsell-table")
$aTableData = _IETableWriteToArray($oTable)
_ArrayDisplay($aTableData)

However, if you look closer at the table, you'll see that it uses custom element "offers", which may not get processed correctly with _IETableWriteToArray

P.S. You can also use the Developer Tools in IE, but I've found it to be slow and often hangs

P.P.S. Searching for the price is a bad idea since they change regularly.

Share this post


Link to post
Share on other sites

Hi Danp2.

I thought I needed to start a new thread, because my topics was two different things.

I added your suggestion, but this is what I get.

How can I find the 36000, 48000 and 60000?

 

image.png.f418b63a092871e41b2afb26b534de91.png


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Like I suspected, _IETableWriteToArray doesn't correctly handle the custom elements. You will need to manually retrieve and process these elements to obtain the information you desire.

You've been around here long enough to know better than to continue asking others to write code for you. Put in some effort, and then come back and show us what you tried thus far.

Share this post


Link to post
Share on other sites

Of course I will do that, but I'm not sharp in how html works.

I was not aware that is was a custom elements.

But thank you for your help, if that matters. :)


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Maybe someone can guide me to what kind of _IE commands I need to look at if I would like to retrieve metadata from "tr" and "td"?

I think I need to collect all of the "TR" and then narrow down my search by looking for "TD", but I don't know what commands I should use.

Thank you in advanced.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

No they are located inside <p> tags as innerText.  You can use "outboundF2" object to get only the right information.

ps. and I agree with @Danp2, you should have kept the first thread open instead of making a new one...

Edited by Nine

Share this post


Link to post
Share on other sites

@Danp2 Yes, I did as I did with:
_IEFormElementGetCollection
_IEFormElementGetObjByName
_IEFormGetCollection
_IEFormGetObjByName

But I just couldn't see how I can use them and that's why I just needed a hint.

@Nine I thought I had to create a new thread, because I felt it was another issue. But I will, if I have another issue, keep in the same thread.
 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Okay, I looked into the _IETagNameGetCollection example and used the F12 on IE so I could see the source.

It of course make sence, because I can see the "type" of the input, but I don't understand how I can get anything out of _IETagNameGetCollection in my project.

I tried to follow the example from the help, but I only get errors.

Error:

$sTxt &= $oOffer.class & @CRLF
$sTxt &= $oOffer^ ERROR

I'm sorry for my lack of knowledge of this. I'm not trying to be lazy, but I really don't understand it.

#include <Constants.au3>
#include <IE.au3>
#include <Array.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, $aTableData
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")
Local $sTxt = ""
For $oOffer In $oOffers
    $sTxt &= $oOffer.class & @CRLF
Next
MsgBox($MB_SYSTEMMODAL, "", "Form: " & $oOffer & @CRLF & @CRLF & "         Types :" & @CRLF & $sTxt)
ConsoleWrite("Done" & @CRLF)

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Hey try this instead :

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

Local $sOrigin = "CPH", $sDest = "EWR", $sDepart = "20210116", $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)
Local $oWarn = _GetObj ($oIE, "got-it", 3000)
If Not IsObj($oWarn) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Unable to get warning screen")
$oWarn.click()
_IELoadWait($oIE)
Local $oTable = _GetObj($oIE, "outboundF2", 2000)
If Not IsObj($oTable) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Unable to get price table")
Local $oTags = _IETagNameGetCollection($oTable,"p")
For $oTag in $oTags
  ConsoleWrite ($oTag.innerText & @CRLF)
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

 

Share this post


Link to post
Share on other sites

@Nine I can only say "wow". I do get feedback 36000, 48000 and 60000.

But this is because you know upfront that "outboundF2" exist, but how do I get others outbound.

In my search I see there's 3 outbound and the first is "outboundF0" and the last is "outfoundF2", but if I search the day before then the result is not chronological order. It's as you see in the attachment.

https://www.sas.dk/book/flights?search=OW_CPH-EWR-20210116_a2c0i0y0&view=upsell&bookingFlow=points&sortBy=stop&filterBy=all

image.png.b19048dc8a6d0e959a4b195ac16626a2.png

I was thinking of counting how many "offers" I could find, but that will not do me good as the first is outboundF2 as I was hoping it was outboundF0 all the time.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Hey,

I have no idea how these things work, but just an idea here. Would this work?

for $i = 0 to 5 ; Change 5 with some other number if you will
    Local $oTable = _GetObj($oIE, "outboundF" & $i, 2000)
    
    If Not IsObj($oTable) Then
        MsgBox ($MB_SYSTEMMODAL,"","Unable to get price table for outboundF" & $i)
    Else
        ConsoleWrite ("OutboundF" & $i & @CRLF)
        Local $oTags = _IETagNameGetCollection($oTable,"p")
        For $oTag in $oTags
            ConsoleWrite ($oTag.innerText & @CRLF)
        Next
    EndIf
Next

 

Edited by GokAy
Changed conbsolewrite part I added

Share this post


Link to post
Share on other sites

Not a bad approach you are proposing @GokAy.  Only question left is if OP needs to get the proper order of outboundF.  I mean is it important to know that the first is (like in his example) 2 than 0 than 1.  If it not important I believe your solution could work.  If not then we need to take another approach, based on a higher object id "outbound-upsell-table" and drill down to each outbound (in the right order) than inspect each component within.

Share this post


Link to post
Share on other sites
1 hour ago, Valnurat said:

In my search I see there's 3 outbound and the first is "outboundF0" and the last is "outfoundF2", but if I search the day before then the result is not chronological order. It's as you see in the attachment.

From this statement (and the following image), my understanding is 2,0,1 is not in chronological order, and previous day was, which seems like 0,1,2. However, as I said I have no idea how these (internet stuff) work. So, I will leave it up to you guys :) 

Share this post


Link to post
Share on other sites
7 hours ago, GokAy said:

From this statement (and the following image), my understanding is 2,0,1 is not in chronological order, and previous day was, which seems like 0,1,2. However, as I said I have no idea how these (internet stuff) work. So, I will leave it up to you guys :) 

That's true, but my first post was sunday and the outbound is in chronological order. But if I search saturday it is not in chronological order as you can see in the latest post.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites
On 11/15/2020 at 2:28 AM, Danp2 said:

Change this to "className" instead of "class" and it should work.

Yes, I got what I expected. Thank you.

If I do below code, I get how many rows "offers" exist in:

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

But if I want to collect the "tr" and it parameters, that is below in the "offers", as you see in the picture:

image.thumb.png.dedb9cbec4f084a913a82ecd277b051e.png

how should I accomplish to get the ID that belongs to that "tr". The only difference between them is the ID.


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

I think I got it by doing this:
 

$oTrs = _IETagNameGetCollection($oIE, "tr")
For $oTr In $oTrs
    If $oTr.className = 'product-column-wrap' Then
        ConsoleWrite("New ID" & @CRLF & $oTr.id & @CRLF & @CRLF)
    EndIf
Next

No, I can't use that solution, because I can see there's cases where 'product-column-wrap' exist on some "tr", but no id attach.

But if it can be done like it belongs together as mentioned in previous post, it could be nice.

Edited by Valnurat

Yours sincerely

Kenneth.

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...