Jump to content

Reading data from a website that is making it difficult!


Go to solution Solved by OJBakker,

Recommended Posts

Posted

I'd like to compile some flight status info from https://www.loganair.co.uk/login/flight-status/

Because the page uses a post mechanism to drill down to the relevant data, I'm not sure how to automate that.

Instead, I'm using shellexecute to open Chrome to the URL, then luckily, because "Kirkwall" is the first "K" in the pulldown list, I can open the URL in a browser, do a send("{TAB 14}K") which loads the data of interest (although it fails pretty regularly, instead resulting in a spinning icon).  After waiting a few seconds, I send("^a^c") then use clipget().  I can then deal with the data as I want.

Several problems:

1) The page fails as mentioned although maybe LoganAir is limiting status requests from one IP or something?

2) Actually opening a visible page and interacting means if I'm using the same computer for anything else, I can accidently screw up the active window during the process, resulting is all sorts of bad results.

3) If I wanted to load data from another airport that wasn't the first listing of that letter, my approach wouldn't work, since it's not a text box.

shellexecute("https://www.loganair.co.uk/login/flight-status/")
winwait("Flight Status")
winactivate("Flight Status")
send("{TAB 14}K")
sleep(5000)
send("^a")
sleep(2000)
send("^c")
sleep(2000)
$data=clipget()
send ("^W")

I see there's a Chrome UDF but it wasn't clear if it would help me, so I've deferred that learning curve.  I tried IE_Create/Read and they just open a flag page that IE is deprecated.  Inetget just gets the initial selection page.  I've tried adding parameters to the URL with no luck, although I'm wading over my depth with that stuff.

 

  • Solution
Posted

1 and 2: use window handles when possible. use ControlSend() to make sure your send() don't go wild on other pages.

3: even when it is some sort of smart-edit you can still send the entire airport name of enough of the name to select the one you want.

You can also use cursor up/down in your 1 letter approach, but than you need to know exactly how many cursor moves you need. 

You can avoid counting tabs from the start of the page by using browsersearch to move to the selection item.

Then your script will be less vulnerable to changes of the entire page unrelated to the item you want to change.

The code below demonstrates the points i mentioned before.

The sleep(2000) are only needed to visually inspect what is happening on screen.

Some are not needed, some may be set to much lower sleep-time.

 

shellexecute("https://www.loganair.co.uk/login/flight-status/")
Local $hWin = winwait("Flight Status")
winactivate($hWin)
ControlSend($hWin, "", "" , "{HOME}") ; make sure you are at the top of the page
sleep(2000)
ControlSend($hWin, "", "" , "^f") ; start browser find
sleep(2000)
ControlSend($hWin, "", "" , "Select an airport") ; search text on page
sleep(2000)
ControlSend($hWin, "", "" , "{ESC}") ; cancel find, virtual-tab postion remains on selected text
sleep(2000)
ControlSend($hWin, "", "" , "{TAB}") ; tab moves from virtual-tab postion to next real tab position. (depending on the page and position sometimes shift-tab is needed, or a few tab/shift-tab)
sleep(2000)
ControlSend($hWin, "", "" , "Bir") ; this will select airport Birmingham
sleep(5000)
ControlSend($hWin, "", "" , "^a") ; select all
sleep(2000)
ControlSend($hWin, "", "" , "^c") ;'copy all
sleep(2000)
$data=clipget() ; copy data from clipboard
ControlSend($hWin, "", "" , "^+{HOME}", "control-shift-HOME cancels the control-a (select all)")
ControlSend($hWin, "", "" , "^W")

 

Posted

Thanks!  It looks like it should work, but I have yet to get past the spinning icon.  I don't know if it's web traffic or some sort of geographical restriction.  I'll try a UK VPN...or try in an hour.

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