I am trying to get sum of some number from a web page.And all number is inside span tag.
This is the webpage - http://py4e-data.dr-chuck.net/comments_42.html
And here is my code:
# To run this, download the BeautifulSoup zip file
# http://www.py4e.com/code3/bs4.zip
# and unzip it in the same directory as this file
from urllib.request import urlopen
from bs4 import BeautifulSoup
import ssl
sum = 0
li = []
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
url = input('Enter - ')
html = urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")
# Retrieve all of the span tags
tags = soup('span')
for tag in tags:
li.append(int(tag.contents[0]))
#x = list(map(int,li))
#print(sum(x))
print(li)
print(sum(li))
But i am getting an error is ‘TypeError: ‘int’ object is not callable’.
Here is my screenshot:
Can you please help me to figure out why this happening ?