Skip to content

Instantly share code, notes, and snippets.

@djinn
Created July 15, 2016 07:12
Show Gist options
  • Save djinn/caff94cd59d02248da63bd894c671477 to your computer and use it in GitHub Desktop.
Save djinn/caff94cd59d02248da63bd894c671477 to your computer and use it in GitHub Desktop.
Download entire Indian Banks IFSC code database as xls files
#!/usr/bin/env python
#pip install requests
#pip install bs4
#Author: Supreet Sethi <supreet.sethi@gmail.com>
#Date: Fri Jul 15 14:11:38 WIB 2016
#License: MIT
from requests import get
import cookielib
from bs4 import BeautifulSoup
import re
from os.path import basename
jar = cookielib.CookieJar()
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'}
u = get("https://www.rbi.org.in/Scripts/bs_viewcontent.aspx?Id=2009", cookies=jar)
soup = BeautifulSoup(u.content)
ulist = soup.findAll("a", href=re.compile('xls$'))
for xl in ulist:
dataurl = xl['href']
if dataurl.startswith("http://"):
dataurl = 'https://' +dataurl[7:]
print dataurl
xlfd = get(dataurl, cookies=jar)
fname = basename(dataurl)
writefd = open(fname, 'w')
writefd.write(xlfd.content)
writefd.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment