Skip to content

Instantly share code, notes, and snippets.

@svineet
Created April 6, 2013 08:23
Show Gist options
  • Save svineet/5325385 to your computer and use it in GitHub Desktop.
Save svineet/5325385 to your computer and use it in GitHub Desktop.
A gist to gather the whole merchant of venice explanation from 'SparkNotes' named website.
import requests
import BeautifulSoup
def main():
print "Hey! Let's start Doing things"
done=False; i = 0 ; acc = "<html><body>"
while (i<=50):
i = i + 2
print "Getting {0}".format(i)
r = requests.get(
'http://nfs.sparknotes.com/merchant/page_{0}.html'.format(i)
)
if r.status_code == 200:
print "Got it! Parsing it now."
soup = BeautifulSoup.BeautifulSoup(r.content)
if soup.find(id='noFear-comparison') == None:
break
else:
acc += '<hr/>' + str(soup.find(id='noFear-comparison'))
else:
print "Ooops, looks like something went wrong!\n Exiting!"
file1 = open('merchant.html','w')
print "Writing to file now!"
file1.write(acc+'</body></html>')
print "Done!"
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment