tuxmartin

angee kickstarter

Sep 15th, 2015
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. from urllib2 import Request, urlopen, URLError
  2.  
  3. someurl = 'https://www.kickstarter.com/projects/tomtu/angee-the-first-truly-autonomous-home-security-sys'
  4.  
  5. req = Request(someurl)
  6. try:
  7.     response = urlopen(req)
  8. except URLError as e:
  9.     if hasattr(e, 'reason'):
  10.         print 'Chyba'
  11. else:
  12.     the_page = response.readlines()  # read each line of the html file
  13.     for line in the_page:  # iterate through the lines
  14.  
  15.         if 'data-goal' in line:
  16.             words = line.split(" ")  # split line into 'words'
  17.             for word in words:  # iterate through 'words'
  18.                 if 'data-goal' in word:
  19.                     target = word.split('"')  # split word at " character
  20.                     # make 2nd element a float
  21.                     print 'target: %.2f' % float(target[1])  # then truncate to 2 d.p.
  22.                 if 'data-percent-raised' in word:
  23.                     percent = word.split('"')
  24.                     print 'percentage raised: %.2f' % (float(percent[1]) * 100)
  25.                 if 'data-pledged' in word:
  26.                     amount_raised = word.split('"')
  27.                     print 'Total so far: %.2f' % float(amount_raised[1])
  28.             print ' '  # stick a blank line on the end
  29.             break  # break out of th
Advertisement
Add Comment
Please, Sign In to add comment