Created
October 17, 2011 06:12
-
-
Save artursapek/1292040 to your computer and use it in GitHub Desktop.
comet_scrape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from BeautifulSoup import BeautifulSoup | |
from mechanize import Browser | |
def CometScrape(date): | |
br = Browser() | |
entry = None | |
br.open('http://www.comettavern.com/shows.php') | |
br.select_form(nr=0) | |
form = br.form | |
month = ['January', 'Feburary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][int(date[0:2]) - 1] | |
day = str(date[2:4]) | |
br['month'] = [month] | |
results = br.submit(name='submit').read() | |
soup = BeautifulSoup(results) | |
for main in soup('div', id='main'): | |
for link in main('a'): | |
if day in str(link.renderContents): | |
print link.renderContents() | |
try: | |
entry = br.follow_link(text=link.renderContents(), nr=0).read() | |
except: | |
print "Broken link or something :(" | |
break | |
if entry: | |
soup = BeautifulSoup(entry) | |
for bands_div in soup('ul', id='bandsMain'): | |
for band in bands_div('li'): | |
bandName = band.renderContents() | |
for a in band('a'): | |
bandName = a.renderContents() | |
print bandName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment