Jump to content
Sign in to follow this  
xeshan

Can I save pdf files from a website with inetget

Recommended Posts

xeshan

Hello,

I am attempting to save pdf files from a work website.

I know inetget allows to save a specific file from a website, but is it possible to specify a file 'type' instead of the specific file name?

In other words,

; Advanced example - downloading in the background
Local $hDownload = InetGet("http://myworksite/folder/dir", @TempDir & "\*.pdf", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload)   ; Close the handle to release resourcs.
MsgBox(0, "", "Bytes read: " & $nBytes)

Is something like this possible?

Please let me know,

Thank you Gurus!

Share this post


Link to post
Share on other sites
wakillon

No, you must list all pdf and download them one by one...

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites
spudw2k

I've built such a script myself recently to accommodate this same task. Lemme look for it.

edit: Here's the script. You'll have to tailor it to your needs, but this should put you in the right direction with a running start.

edit:

I also must mention that I arbitrarily did a StringRight to trim the file names, but this only worked because all the files had the same length of chars. You'll have to decide how to name the saved files.

#include <IE.au3>
$oIE = _IECreate("archive.wmlnj.org/TheWeatherVane/1973/")
$oLinks = _IELinkGetCollection ($oIE)
If @error Then
    msgbox(0,"Failed To Navigate to Webpage","")
    Exit
EndIf
$savedir = FileSelectFolder("Save PDFs To","",5,@ScriptDir)
If Not $savedir Then Exit
For $oLink In $oLinks
    If StringInstr($oLink.href,".pdf") Then
        ConsoleWrite(InetGet($oLink.href,$savedir & "\" &
StringRight($oLink.href,11))&@CRLF)
    EndIf
Next
msgbox(0,"Done","")
Edited by spudw2k

Share this post


Link to post
Share on other sites
xeshan

Thank you spudw2k!

I modified your script slightly if it may be of help for some other users.

Thank you again.

#include <IE.au3>
$oIE = _IECreate("archive.wmlnj.org/TheWeatherVane/1973/")
$oLinks = _IELinkGetCollection ($oIE)
If @error Then
    msgbox(0,"Failed To Navigate to Webpage","")
    Exit
EndIf
$savedir = FileSelectFolder("Save PDFs To","",5,@ScriptDir)
If Not $savedir Then Exit
For $oLink In $oLinks
    If StringInstr($oLink.href,".pdf") Then
        ConsoleWrite(InetGet($oLink.href,$savedir & "\"  & _GetFullNameByUrl ( $oLink.href ), 1, 0))
StringRight($oLink.href,11)
    EndIf
Next
msgbox(0,"Done","")


Func _GetFullNameByUrl ( $_FileUrl )
    $_FileName = StringSplit ( $_FileUrl, '/' )
    If Not @error Then
        Return $_FileName[$_FileName[0]]
    Else
        Return 0
    EndIf
EndFunc  ;==>  _GetFullNameByUrl ( )

Share this post


Link to post
Share on other sites
spudw2k

I updated my script and made it more versatile. It also provides useful visual feedback as it runs. Still could use some optimizing and cleanup.

edit: Whoops, wrote in an older version which didn't support @Inet macros. Updated to 3.3.6.1

#include <IE.au3>
$url = InputBox("URL to download from?","","archive.wmlnj.org/TheWeatherVane/1973/")
$linktype = InputBox("Links to download?","What type of links?",".PDF")
ProgressOn("Navigating to URL","Finding Links")
$oIE = _IECreate($url,0,0)
If @error Then
    msgbox(0,"Failed To Navigate to Webpage","")
    Exit
EndIf

$oLinks = _IELinkGetCollection ($oIE)
Dim $arrLinks[1]
$arrIdx = 0
For $oLink In $oLinks
    If StringInstr($oLink.href,$linktype) Then
        ReDim $arrLinks[UBound($arrLinks)+1]
        $arrIdx+=1
        $arrLinks[$arrIdx]=$oLink.href
    EndIf
Next
$arrLinks[0]=UBound($arrLinks)
_IEQuit($oIE)

ProgressOff()
If UBound($arrLinks)<=1 Then
    msgbox(0,"No " & $linktype & " links found.","")
    Exit
EndIf

$savedir = FileSelectFolder("Save Links to","",1,@ScriptDir)
If Not $savedir Then Exit
ProgressOn("Downloading Links","")

For $i = 1 to $arrLinks[0]
    $size = Int(InetGetSize($arrLinks[$i])/1024)
    ProgressSet(0,"","Downloading " & $i & " of " & $arrLinks[0])
    $savefile = StringTrimLeft($arrLinks[$i],StringInstr($arrLinks[$i],"/",0,-1))
    $hDownload = InetGet($arrLinks[$i],$savedir & "\" & $savefile,1,1)
    Do
        sleep(250)
        $data = Int(InetGetInfo($hDownload,0)/1024)
        ProgressSet(($data/$size)*100,$savefile & @CRLF & $data & "KB of " & $size & "KB","Downloading " & $i & " of " & $arrLinks[0])
    Until InetGetInfo($hDownload,2)
Next

msgbox(0,"Done","")
Edited by spudw2k

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
Sign in to follow this  

×