TCS IT Wiz is coming up (the Kolkata edition’s on the 9th) and that means a lot of research work, especially from Wikipedia. So, I wrote up a quick tool to export Wikipedia pages as PDFs. First, install Python 2.7 from here and download the following script:

import requests
import bs4
import io

ADD_URI = '{0}&oldid=0'

def wikify(topic):
    return '+'.join(topic.split(' '))

def main(args):
    print '[ Wikipdf ]'
    print '(C) 2012 Aviral Dasgupta -'
    if len(args) < 2:
        print 'Usage: {0} <>'.format(args[0])

    with[1], 'r') as page_list:
        topics = map(lambda t: t.strip(), page_list.readlines())

    print 'Downloading: ' + ', '.join(topics) + '.'
    print '({0} pages; this may take a while)'.format(len(topics))

    s = requests.session()

    for topic in topics:
        print 'Adding {0}'.format(wikify(topic))

    print 'Done.'
    p =, {'formatSelect': 'rl', 'bookcmd': 'render'})

    print 'Rendering...'
    print 'Render progress page is at {0}'.format(p.url)
    print 'You can check manually or allow Wikipdf to check and download.'
    opt = raw_input('Open web browser with progress page url? [Y/N]')
    if opt.lower().strip().startswith('y'):
        import webbrowser

    t = 1
    while True:
        import time
        print 'Checking ({0}) ...'.format(t)
        t += 1
        p = s.get(p.url)
        if 'finished' in p.text:

    print 'Rendering done; downloading.'
    soup = bs4.BeautifulSoup(p.content)
    pdfuri = soup.find_all('a')[3]['href']

    content = s.get(pdfuri).content

    with[1] + '.pdf', 'wb') as out:

if __name__ == '__main__':
    import sys

Then, install PIP by downloading and running and execute the following commands:

aviraldg@aviraldg-netbook:~$ pip install beautifulsoup4
aviraldg@aviraldg-netbook:~$ pip install requests

Now, just create a text file which lists all the topics you want to download, each on a new line, and drag this file on top of the wikipdf script (or execute it from the terminal with the list file as an argument.)

Comment if you have problems or want to offer feedback.