Skip to content

Instantly share code, notes, and snippets.

@MichelleDalalJian
Last active November 18, 2023 00:44
Show Gist options
  • Save MichelleDalalJian/2c9aaadbda21290e1ccfc87a9ab1f937 to your computer and use it in GitHub Desktop.
Save MichelleDalalJian/2c9aaadbda21290e1ccfc87a9ab1f937 to your computer and use it in GitHub Desktop.
Scraping Numbers from HTML using BeautifulSoup. The program will use urllib to read the HTML from the data files below, and parse the data, extracting numbers and compute the sum of the numbers in the file.
#Actual data: http://py4e-data.dr-chuck.net/comments_24964.html (Sum ends with 73)
from urllib import request
from bs4 import BeautifulSoup
html=request.urlopen('http://python-data.dr-chuck.net/comments_24964.html').read()
soup = BeautifulSoup(html)
tags=soup('span')
sum=0
for tag in tags:
sum=sum+int(tag.contents[0])
print(sum)
@Mk-Hamzaoui
Copy link

image
c'est quoi le probleme

@Mk-Hamzaoui
Copy link

jai essaie sur vs code il y a un probleme trace back et maintenant sur jupyter toujours le resultat 0

@Albedo100
Copy link

uninstall the zip folder and the extracted folder of bs4 and install it using your command prompt by typing: -
pip install beautifulsoup4

@katsuspec
Copy link

ayuda1
ayuda1 1
help mee pls
Sum: ???
Code: ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment