r/ScriptSwap • u/deathbybandaid • Sep 09 '15
Pdf Scraper
Request: I collect lego sets, and I'd like to build a tool to "scrape" all of the free instruction manuals that Lego provides at:
http://service.lego.com/en-us/buildinginstructions
Is this possible?
7
Upvotes
3
u/SikhGamer Sep 23 '15
Here you go mate, this will get all PDF download links. There may be some duplicates so you can use Excel to remove those. Or let your download manager do it for you. Takes around 180 seconds to run for me. The download links are written to a file called downloadLinks.txt
1
u/Sn0zzberries Sep 09 '15
All instructions seem to be PDFs named with 7 digits. (There could be alpha chars too)
Don't have time to build it, but sudo-code up above. You may run into issues with requests per second limiting.
1
u/SikhGamer Sep 21 '15 edited Sep 23 '15
This is PowerShell, it'll print out the PDF download link. I'd suggest saving the output to a text file and using your favourite download manager to download them.foreach($year in 1989..2015) { $result = Invoke-WebRequest -Uri ("http://service.lego.com/Views/Service/Pages/BIService.ashx/SearchByLaunchYear?searchValue=$year&fromIdx=0") -UseBasicParsing $payload = $result.content | ConvertFrom-Json $payload.Content.PdfLocation }You will get an output likethisEdit* This script does not grab all PDF links.
0
u/roodpart Sep 09 '15
for ($i = 0000000; $i -le 999999; $i++)
{
wget http://cache.lego.com/bigdownloads/buildinginstructions/$i.pdf
}
I was working on this but i've ran out of time and have to leave but here it is maybe someone could fix it.
0
u/blaize9 Sep 09 '15 edited Sep 11 '15
You can scrape http://service.lego.com/Views/Service/Pages/BIService.ashx/SearchByLaunchYear?searchValue=2015&fromIdx=0
Just keep on looping & incrementing fromIdx by 22 until MoreData == false and then go down a year and reset the Idx back to 0.