i am taking an assignment of Assignment C12 Scraping HTML Data with BeautifulSoup
print('Scraping HTML Data with BeautifulSoup')
# 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
#Sample:
http://py4e-data.dr-chuck.net/comments_42.html (Sum=2553)
#Actual:
http://py4e-data.dr-chuck.net/comments_1578834.html (Sum ends with 75)
from urllib.request import urlopen
from bs4 import BeautifulSoup
import ssl
# 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()
print('BeautifulSoup Issues ')
print('
https://github.com/csev/py4e/issues/335 ')
print('element.py", line 1565, in _normalize_search_value')
print('AttributeError: module -collections- has no attribute -Callable-')
#soup = BeautifulSoup(html, "html.parser")
#x = soup('a')
import urllib.request, urllib.parse, urllib.error
import re
suma = 0
val = 0
numlist = list()
tags = urllib.request.urlopen(url)
for tag in tags:
#print(line.decode().strip())
tagd = tag.decode().rstrip()
if tagd.startswith('<tr><td>'):
#print('tagd:',tagd)
y = re.findall('([0-9]+)', tagd)
if y == []: continue
ly=(len(y))
val = val + ly
for word in y:
x = int(word)
numlist.append(x)
suma = suma + x
else: continue
print(' ')
print('suma:',suma)