Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib2 import Request, urlopen, URLError
- someurl = 'https://www.kickstarter.com/projects/tomtu/angee-the-first-truly-autonomous-home-security-sys'
- req = Request(someurl)
- try:
- response = urlopen(req)
- except URLError as e:
- if hasattr(e, 'reason'):
- print 'Chyba'
- else:
- the_page = response.readlines() # read each line of the html file
- for line in the_page: # iterate through the lines
- if 'data-goal' in line:
- words = line.split(" ") # split line into 'words'
- for word in words: # iterate through 'words'
- if 'data-goal' in word:
- target = word.split('"') # split word at " character
- # make 2nd element a float
- print 'target: %.2f' % float(target[1]) # then truncate to 2 d.p.
- if 'data-percent-raised' in word:
- percent = word.split('"')
- print 'percentage raised: %.2f' % (float(percent[1]) * 100)
- if 'data-pledged' in word:
- amount_raised = word.split('"')
- print 'Total so far: %.2f' % float(amount_raised[1])
- print ' ' # stick a blank line on the end
- break # break out of th
Advertisement
Add Comment
Please, Sign In to add comment