nick34992
5/30/2016 - 9:43 AM

Python BeautifulSoup Scrape Span Numbers

Python BeautifulSoup Scrape Span Numbers

#!/usr/bin/python2.7

import urllib
from BeautifulSoup import *
# http://python-data.dr-chuck.net/comments_276693.html
url = raw_input('Enter URL: ')
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
spans = soup('span')
numbers = []
counter = 0
for span in spans:
    numbers.append(int(span.string))
    counter += 1
print 'Count ', counter
print 'Sum ', sum(numbers)