python / BeautifulSoup

Skip to first unread message

Sergio Gonzalez Gutierrez

Jul 22, 2022, 4:46:37 AMJul 22
to beautifulsoup
i am taking an assignment of Assignment C12 Scraping HTML Data with BeautifulSoup

as Saleem I took all the measures but it doesn´t  work

does anyone give some support:
print('Scraping HTML Data with BeautifulSoup')
# To run this, download the BeautifulSoup zip file
# and unzip it in the same directory as this file

#Sample: (Sum=2553)
#Actual: (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(' ')

print('", 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:
    tagd = tag.decode().rstrip()
    if tagd.startswith('<tr><td>'):
        y = re.findall('([0-9]+)', tagd)
        if y == []: continue
        val = val + ly
        for word in y:
            x = int(word)
            suma = suma + x
    else: continue
print(' ')

# Retrieve all of the anchor tags
#tags = soup('a')
#for tag in tags:
    # Look at the parts of a tag
    #print('TAG:', tag)
    #print('URL:', tag.get('href', None))
    #print('Contents:', tag.contents[0])
    #print('Attrs:', tag.attrs)

Thanks in advance

Reply all
Reply to author
0 new messages