Skip to content

Instantly share code, notes, and snippets.

@rikva
Created April 24, 2012 09:50
Show Gist options
  • Save rikva/2478460 to your computer and use it in GitHub Desktop.
Save rikva/2478460 to your computer and use it in GitHub Desktop.
Simpel Python script om de huidige NRC Next PDF te downloaden en te openen (voor NRC Next abonnees)
#!/usr/bin/env python
from sys import argv, exc_info
from mechanize import Browser
from datetime import datetime
from subprocess import call
pdfreader = '/usr/bin/okular'
if len(argv) == 3:
try:
datestring = datetime.now().strftime('%Y%m%d')
br = Browser()
br.open('https://login.nrc.nl/login?service=http://digitaleeditie.nrc.nl/digitaleeditie/')
br.select_form(nr=0)
br['username'], br['password'] = argv[1], argv[2]
br.submit()
print 'Retrieving PDF file ...'
pdffile = br.retrieve('http://digitaleeditie.nrc.nl/digitaleeditie/helekrant/fullpdf/%s_NRC_Next.pdf' % datestring)[0]
call([pdfreader, pdffile])
except:
print "ERROR: %s" % exc_info()[1]
else:
print 'USAGE: python file.py <username> <password>'
@wybodekker
Copy link

Ik krijg:
ERROR: HTTP Error 405: Method Not Allowed

@rkrijnen
Copy link

rkrijnen commented Nov 1, 2014

Simply removing ?service=http://digitaleeditie.nrc.nl/digitaleeditie/ from the br.open() command dit the trick...

@wybodekker
Copy link

Works - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment