SOLVED

Download Specific Files From Link

Brass Contributor

https://www.fbi.gov/wanted/topten/alejandro-castillo/download.pdf 

Hi here is the link i need to download the file , between the /topten and /download.pdf is the person name. And the website will update everyday so if i want download all the file how can i write. Cuz if i just use the link https://www.fbi.gov/wanted/topten is will jump out the message:Content-Disposition header not found for URL: https://www.fbi.gov/wanted/topten

20 Replies

@YeuHarng 

 

I wrote this to parse the parse, quick but this works:

 

 

$toptenpage = Invoke-WebRequest -Uri https://www.fbi.gov/wanted/topten -UseBasicParsing 
$urls = ($toptenpage.Links | Where-Object { $_.href -Match 'topten' -and $_.href -notmatch 'History' -and $_.href -notmatch 'faq' }).href |  Sort-Object | Select-Object -Unique -Skip 2
foreach ($url in $urls) {
    Invoke-WebRequest -Uri "$($url)/download.pdf" -UseBasicParsing -OutFile "c:\temp\$($url.Split('/')[5]).pdf"
}

 

 

This will save, create c:\temp if not already present, the top ten people in a .pdf file per person:

 

Harm_Veenstra_0-1693825128361.png

 

Please let me know if it works also for you and mark my answer as Solution to mark this topic as solved if it did

best response confirmed by YeuHarng (Brass Contributor)
Solution

@Harm_Veenstra 

Hi, thankieww for u helping but still have error, i'm a newbie in PowerShell, can u explain what does this mean?

YeuHarng_0-1693831008058.png

 

Ah, there seems to be a policy in place on your system. Does it work if you run Set-ExecututionPolicy Bypass and then run the script in the same PowerShell prompt?

yeah, it works thankieww so much! i keep going to learn , if have any question i will ask u again , TQSM!
No problem ;) Please mark my first answer as Solution to mark this topic as solved
Thanks, but you should mark my answer as solution and not your reply ;)
where can mark it i can;t find
Mark as best response should be visible
hi, for the other category just can download the first 40 pdf because the website didnt scroll down to refresh until the end, so is that any function can let it scroll down until the end and let me download ?
That's the https://www.fbi.gov/wanted/fugitives page, for example? The invoke-webrequest only gets the first page and not the whole page if that is expanded by scrolling
ya, is that just can use import Selenium module?
No experience with that myself, but that seems like an option, I guess?
its ok then i try myself tqsm ya

for this link: https://www.un.org/securitycouncil/content/un-sc-consolidated-list 
here have the download pdf download button, is that possible to get the button link or what and download the file, because jn i use the link, then the message say:the link cannot find the file. or also need to import the Selenium? Because based on my research if the need action with the web browser so need to import Selenium

YeuHarng_0-1694077480846.png

 

Not sure what the button does, it could render the page for you and be a different link every time?
nope, the link is the same, but not sure can get the link or not , because that is the button
Sorry, I didn't explain it correctly... I wanted to say that the button is an action to print the current browser output to PDF. Not sure if you can download that because there is a Print to PDF and save the file to prompt...
okay nvm its ok

@Harm_Veenstra hi sry again to bother u.last time u send me the code, on that day I can run,but tdy I don’t know why can’t can u try on ur site ?