python / BeautifulSoup

109 views
Skip to first unread message

Sergio Gonzalez Gutierrez

unread,
Jul 22, 2022, 4:46:37 AM7/22/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
# 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)

# 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
Forward
0 new messages