jksmurf Posted February 20, 2011 Share Posted February 20, 2011 (edited) I think I've gone as far as my feeble coding efforts allow (apologies to clean neat coders), but now I'm stuck, and I don't know why. It's a pretty simple script (explanation what it does is in the code below), and it runs the first round of what I want it do, but then seems ot hand, and I have to select tools stop executing to bail out. There's no obvious error messages. Appreciate all and any help on this issue, and if anyone wants to have a dig at my code with (heopefully positive) suggestions for improvement, I'd be happy to hear those too. Cheers k. expandcollapse popup; MAIN: Open Setanta Website and Save Each Javascript Generated EPG File for TVxB to Process ; ; This script is to download a series of webpages for a TV EPG, that can processed by TVxB, a "scraper" which uses wget. ; The TV EPG site to scrape uses Javascript, so the wget doesn't work. This script: ; 1. Loads http://www.setanta.com/HongKong/TV-Listings/ which loads today's EPG. ; 2. Save that web page to a local dir in the format TVxb-Setanta.hk-20110215.html so that TVxB can parse it. ; 3. Clicks the NEXT date which uses Javascript in the form javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl02$btnDay','') to load the next days page. ; 4. Saves that web page to a local dir in the fromat TVxb-Setanta.hk-20110216.html, Web Page, HTML Only so that TVxB can parse it. ; 5. Repeat ; ; You can use the InetGet or the InetRead function in .au3 to download files from websites, but need Javascript so need to open instead. ; $MDAYALT=@MDAY; Declare Variable for File Names ; #include <IE.au3> _IEErrorHandlerRegister() ConsoleWrite("Debug: Main Routine Setanta Window" & @LF) ; $oIE = _IECreate(); Open WebPage ; _IENavigate($oIE,"http://www.setanta.com/HongKong/TV-Listings/"); _IE that navigates to the first page and waits until "done". ; Opens Setanta Website ... _IELoadWait($oIE); _IE loads page and waits until REALLY "Done" to avoid "The Requested Resource Is in Use" Error Messages ... $hIE = _IEPropertyGet($oIE, "hwnd"); get the 'handle' (hwnd) for the IE window opened. ; SaveTVxBhtml(); Save the page by calling the Save Routine; InetGet is no good for Javascript pages as for urls only ; _IENavigate($oIE,"javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl02$btnDay','')"); Return from Save routine and move onto the next day using Javascript command SaveTVxBhtml() ; Call Save Subroutine again, to save it and then Move onto the next day using Javascript command; Save it; etc etc ; _IENavigate($oIE,"javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl03$btnDay','')") ;SaveTVxBhtml() _IENavigate($oIE,"javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl04$btnDay','')") ;SaveTVxBhtml() _IENavigate($oIE,"javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl05$btnDay','')") ;SaveTVxBhtml() _IENavigate($oIE,"javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl06$btnDay','')") ;SaveTVxBhtml() _IENavigate($oIE,"javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$btnNextWeek','')") ; ; Finally, close the Webpages ; ; $hIE = _IEPropertyGet($oIE, "hwnd"); ; WinActivate($hIE) WinWaitActive($hIE) ; _IEQuit ($oIE) ; Func SaveTVxBhtml() $SaveDate = @YEAR&@MON&$MDAYALT ; _IEErrorHandlerRegister() ;$OverWriteYes = _IEPropertyGet($oIE, "DirectUIHWND1"); get the 'handle' (DirectUIHWND1) of the IE Overwrite Dialog Window ; WinActivate($hIE) WinWaitActive($hIE) ConsoleWrite("Debug: Setanta Save File Section" & @LF) ; ControlSend($hIE, "", "", "!f") ; File (Same as Alt-F) ControlSend($hIE, "", "", "a") ; SaveAs (A with Alt-F Open = As) ; WinWait("Save Webpage", "", 5); Wait for the "Save Webpage" Box to Come Up; Noye that in IE6 it might read "Save Web Page" $hSave = WinGetHandle("Save Webpage", "") ; Assign handle of the "Save Webpage" Box to a variable WinActivate($hSave); Activate that page ; ControlFocus($hSave, "", "Edit1"); Switch Focus to Filename within the "Save Webpage" Box Window ControlSend($hSave, "", "[CLASS:Edit; INSTANCE:1]", "C:\Users\Kristian\Desktop\TVxb-setanta.hk-" & $SaveDate); Input Filename WinActivate($hSave); Activate the Save Box to be Sure Sleep (1000); Give it a sec to ensure no keystrokes lost ControlFocus($hSave, "", "ComboBox2"); Switch Focus to ComboBox ControlCommand($hSave, "", "[CLASS:ComboBox; INSTANCE:2]", "SelectString", "Webpage, HTML only"); Switch Selection to Webpage, HTML ONLY in the Type Dropdown WinActivate($hSave); Activate the Save Box AGAIN to be Sure! ControlClick($hSave, "", "[CLASS:Button; TEXT:&Save; INSTANCE:1]"); If the Overwrite Dialog Doesn't come up, Save it anyway! ; If WinExists ("Confirm Save As") Then ;WinWait("Confirm Save As", "", 5); Wait for "Confirm Save As" Box to Come Up ;$hClickYesToOverwrite = WinGetHandle("Confirm Save As", "") ; Assign handle of the Save Web page Box to a variable ;WinActivate($hClickYesToOverwrite); Activate that page ;Sleep (1000); Give it a sec to ensure no keystrokes lost ;ControlClick($hClickYesToOverwrite, "", "[CLASS:Button1; TEXT:&Yes; INSTANCE:1]"); Just Say YES ... save the beasty Sleep (1000) Send ("!Y"); Alternative EASY Method to Click YES ; EndIf ; $MDAYALT=$MDAYALT+1; Increment the Date 1 Day ; EndFuncSetanta.au3 Edited February 20, 2011 by jksmurf Link to comment Share on other sites More sharing options...
BrewManNH Posted February 20, 2011 Share Posted February 20, 2011 Try changing this line: $oIE = _IECreate(); Open WebPage To this and see if it works for you: $oIE = _IECreate("http://www.setanta.com/"); Open WebPage If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
jksmurf Posted February 20, 2011 Author Share Posted February 20, 2011 Nope, it executes the first loop, I see it does line 27 OK (the second date) then just sort of hangs indefintely? k. Link to comment Share on other sites More sharing options...
jksmurf Posted February 22, 2011 Author Share Posted February 22, 2011 Well, a friend helped me get the working, just by adding a ",0)" to end of the ienavigate lines to not wait for page reload,[apparently "because it isn't actually reloading, just using javascript to alter what shows up"]. I am still a bit puzzled how to fix an issue of the default page on the website http://www.setanta.com/HongKong/TV-Listings/ reporting a day that is 1 day earlier than today's actual date (because they haven't updated it yet). Can anyone help advise what I need to do to interrogate the web-page and harvest the date (this is from the view-source), it seems it must be possible to get the date associated with the doPostBack javascript commmand? href="javascript:__doPostBack('ctl00$cphForm$AllCols$tvlHeader$rptDays$ctl01$btnDay','')">Tue, 22 Feb</a> k.Setanta.au3 Link to comment Share on other sites More sharing options...
jksmurf Posted March 3, 2011 Author Share Posted March 3, 2011 Further to this, the script doesn't seem to actually download the next page, even though the script clicks the next day and javascript changes all the TV Guide. All the downlaoded pages are the same? Would really appreciate someone taking a wee look? Thanks k Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now