Created
April 6, 2013 08:23
-
-
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.
This file contains hidden or 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
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