Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
beautifulsoup
#1
Hi!
I've written a programme that use BeautifulSoup. It uses urllib to read the HTML from a file, parse the data, extract numbers from the label span and compute the sum of the numbers in the file.
However, it does not work and when I run it it appears:
ModuleNotFoundError: No module named 'html.entities'; 'html' is not a package

Any ideas what I am doing wrong? My programme:

from urllib.request import urlopen
from bs4 import BeautifulSoup
   


url = input('Enter - ')
archivo = urlopen(url, context=ctx).read()
soup = BeautifulSoup(archivo, "archivo.parser")

suma=0
tags = soup('span')
for tag in tags:

    suma = suma+int(tag.contents[0])
print(suma)
Larz60+ write Dec-26-2021, 01:12 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed ffor you this time. Please use bbcode tags on future posts.
Reply
#2
Post the full traceback. The code you've posted doesn't have an import for html.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020