PDA

View Full Version : VBA - Change the outbound and return times on Skyscanner



fatboy_1989
05-28-2017, 12:07 PM
Hello

How can I change the outbound and return flight time ranges in Skyscanner within VBA?

E.g. London to rome departing London on 20/9/2017 and returning 28/9/2017

I want to in Excel VBA, change the outbound and return times ranges as follows:

Outbound: 08:30 - 16:00
Return: 15:00 - 19:00

For information, the time ranges can be changed on the left hand side menu once clicked the link above

Thanks

Cross Links
ozgrid showthread 204244 (note i am not able to paste links here...)
vbaexpress showthread 59592 (note i am not able to paste links here...)
excelguru showthread 7874 (note i am not able to paste links here...)
excelforum 1187156 (note i am not able to paste links here...)

fatboy_1989
05-29-2017, 01:09 PM
Cross Link: mrexcel 1007442 (note i am not able to post links here)

SamT
05-29-2017, 04:00 PM
You said
For information, the time ranges can be changed on the left hand side menu once clicked the link above
What link?

fatboy_1989
05-30-2017, 01:39 AM
Apologies, I cannot post a link in my post. If you go to skyscanner and search a flight then just use that as an example (the flight and date is not important here it's just the VBA code)
London to Rome departing London on 20/9/2017 and returning 28/9/2017

fatboy_1989
05-30-2017, 07:25 AM
This is proving very difficult as nobody has been able to come up with any solution, even on other forums

fatboy_1989
05-30-2017, 07:26 AM
This may help get an answer or help understand what I am trying to do:

1) Open the skyscanner link in internet explorer
2) Press F12 to open the webpage HTML
3) Select the "DOM Explorer" tab
4) Press Ctrl+B so that you can select a part of the webpage
5) Select the Outbound slider bar right handle (can be found on the LHS of the webpage)
6) It should highlight:

7) Just above this line is a line that ends with something like .....style="left:100%;">
8) If you move the slider bar, this value changes
9) The00:00 – 23:59
also changes when you move the slider right handle
10) It should be the values in either 8) or 9) that I want to be able to change/update via VBA

Note the following will get the time range values that it is currently:


Sub ChangeSkyscannerOutwardTimes()
Dim IeApp As Object
Set IeApp = CreateObject("InternetExplorer.Application")
IeApp.Visible = True
IeApp.navigate "https://www.skyscanner.net/transport/flights/Lond/BERL/170721/170729"
divElem1 = IeApp.document.getElementsByClassName("noUi-origin noUi-connect")
OutwardTimeLeftHandleValue = divElem1.Style.cssText
divElem2 = IeApp.document.getElementsByClassName("noUi-origin noUi-background")
OutwardTimeRightHandleValue = divElem2.Style.cssText
IeApp.Quit
End Sub

fatboy_1989
06-07-2017, 04:39 AM
I have found the rows and have updated the outward and return flight times in the HTML code BUT when I refresh the page, it defaults back to the original times: "00:00 - 23:59". How can I refresh the page so that it now uses what values i've input?

The lines of code relevant are:

IeApp.document.getElementsByClassName("filter-opts slider-opts")(0).getElementsByTagName("div")(0).INNERTEXT = "10:00 – 12:00"
IeApp.document.getElementsByClassName("filter-opts slider-opts")(1).getElementsByTagName("div")(0).INNERTEXT = "08:00 – 22:00"
IeApp.Refresh 'Note this refreshes the webpage but reverts the time ranges i've changed above back to "00:00 - 23:59"