bird42 Posted January 8, 2013 Posted January 8, 2013 (edited) Hi all I'm trying to make a script that automatically downloads issues of my favourite free comic book Here is the code: expandcollapse popup#include <Inet.au3> #include <File.au3> If UBound(ProcessList(@ScriptName)) > 2 Then MsgBox(4096, "Error", @ScriptName&" is already running.", 5) Exit EndIf Global $main = 'site url' Global $file = @ScriptDir&'\log.txt' If FileExists($file)=0 Then FileWrite($file,'First run: '&@YEAR&' '&@MON&@CRLF) TrayTip('No log file found','Assuming this is the first run. Donwloading of all content starting...',30) _getall() Else If FileReadLine($file,-1) <> 'Last run '&@YEAR&' '&@MON Then _checknew() EndIf Exit Func _download($year,$month) TrayTip('Downloading',$main&$year&'/'&StringFormat('%02d',$month),30) $source = StringSplit(_INetGetSource($main&$year&'/'&StringFormat('%02d',$month)),'"') If @error then FileWriteLine($file,'---'&@CRLF&'Not found '&$year&' '&StringFormat('%02d',$month)) SetError(0) Return 0 EndIf For $n= 1 to $source[0] If StringInStr($source[$n],'.pdf') then InetGet($main&$year&'/'&StringFormat('%02d',$month)&'/'&$source[$n],@ScriptDir&'\'&$year&'\'&StringFormat('%02d',$month)&'\'&$n&'.pdf') If @error then MsgBox(16,'ERROR','Download error at '&@CRLF&$main&$year&'/'&StringFormat('%02d',$month)&'/'&$source[$n]) FileWriteLine($file,'---'&@CRLF&'Download error at '&$main&$year&'/'&StringFormat('%02d',$month)&'/'&$source[$n]) SetError(0) Return 0 EndIf Next FileWriteLine($file,'---'&@CRLF&'Success'&$year&' '&StringFormat('%02d',$month)) EndFunc Func _getall() For $i='2012' to @YEAR For $j='01' to '12' _download($i,$j) Next Next FileWriteLine($file,'---'&@CRLF&'Last run '&@YEAR&' '&@MON) EndFunc Func _checknew() TrayTip('Checking...','',30) _download (@YEAR,@MON) EndFunc The problem is that even if i can retrieve the right link i always get download error. Any other suggestions welcome. Regards and sorry for my 'newbieness'. Edited January 8, 2013 by zentral
BrewManNH Posted January 8, 2013 Posted January 8, 2013 (edited) What exactly is this line supposed to be doing? StringSplit(_INetGetSource($main & $year & '/' & StringFormat('%02d', $month)), '"') Edited January 8, 2013 by BrewManNH 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
bird42 Posted January 8, 2013 Author Posted January 8, 2013 (edited) Ahem. As i don't know how to read links from a webpage i figured out to get the source, split it and get the links from here. So this gets the source of the desired webpage. Edited January 8, 2013 by zentral
BrewManNH Posted January 8, 2013 Posted January 8, 2013 What that line does is, it gets the source of the site, and splits it on any double quotes it finds in the text returned. Is that what you're intending for it to do? Have you checked the contents of the array after that has been run to see if it contains what you want it to contain? 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
bird42 Posted January 8, 2013 Author Posted January 8, 2013 It does. However if you have a better way to scan for all the links to a .pdf file in a webpage it would be awesome
BrewManNH Posted January 8, 2013 Posted January 8, 2013 Look at the _IE functions for finding the links, someone more knowledgeable than me would have to help you with that because I almost never use them. 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
Solution GMK Posted January 8, 2013 Solution Posted January 8, 2013 (edited) Quick example:#include <IE.au3> #include <Array.au3> Local $avLinks Local $sURL = "http://www.irs.gov/uac/Forms,-Publications,-and-Other-Tax-Products" Local $oIE = _IECreate($sURL) Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks If StringRight($oLink.href, 4) = ".pdf" Then If Not IsArray($avLinks) Then Local $avLinks[2] = [1, $oLink.href] Else ReDim $avLinks[UBound($avLinks) + 1] $avLinks[0] += 1 $avLinks[UBound($avLinks) - 1] = $oLink.href EndIf EndIf Next _ArrayDisplay($avLinks) ;Then you can loop through the array and use InetGet to download the files Edited January 8, 2013 by GMK
bird42 Posted January 8, 2013 Author Posted January 8, 2013 Thank you very much sir! Really appreciated. I'll study your code:)
GMK Posted January 8, 2013 Posted January 8, 2013 You're welcome--hope it helps. And I changed the Array.au3 include, since the one I had was not standard.
bird42 Posted January 9, 2013 Author Posted January 9, 2013 For $j= 1 to $avLinks[0] TrayTip('Downloading',$avLinks[$j]&' to'& $ddir&$j&StringRight($avLinks[$j], 4),30) InetGet($avLinks[$j],$ddir&$j&StringRight($avLinks[$j], 4)) Next TrayTip('Done','',30) This way?
GMK Posted January 9, 2013 Posted January 9, 2013 That will download the file as 1.pdf, 2.pdf, etc. If that's what you want, then that's fine. You may run into problems if a file by the same name already exists.
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