Advertisement
Guest User

random futurama quote generator

a guest
Sep 5th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1.  
  2. import sys
  3. import requests
  4. import BeautifulSoup
  5.  
  6.  
  7. def extract():
  8.     resp = requests.get('http://subfusion.net/cgi-bin/quote.pl',
  9.                         params={'quote':'futurama', 'number':'1'})
  10.  
  11.  
  12.     soup = BeautifulSoup.BeautifulSoup(resp.text)
  13.  
  14.     for ele in soup.html.body.findAll('b'):
  15.         try:
  16.             for tag in ele.findAll('br'):
  17.                 if isinstance(tag.next, BeautifulSoup.NavigableString):
  18.                     return tag.next.format()
  19.         except:
  20.             pass
  21.  
  22. def main():
  23.     try:
  24.         repeat = int(sys.argv[1])
  25.     except:
  26.         repeat = 1
  27.     for _ in range(repeat):
  28.         print extract()
  29.         print "-" * 75
  30.  
  31. if __name__ == '__main__':
  32.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement