Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Import urllib and beautifulsoup
- from urllib.request import urlopen
- from bs4 import BeautifulSoup
- import ssl
- # 2. Ignore SSL certificate errors
- ctx = ssl.create_default_context()
- ctx.check_hostname = False
- ctx.verify_mode = ssl.CERT_NONE
- # 3. Read HTML with urllib's urlopen() method
- url = input('Enter - ')
- html = urlopen(url, context=ctx).read()
- # 4. Parse HTML with BeautifulSoup's BeautifulSoup() method
- soup = BeautifulSoup(html, "html.parser")
- # 5. Retrieve list of span tags
- tags = soup('span')
- ans = 0
- # 6. Loop through to get numbers
- for tag in tags:
- num = tag.contents[0]
- # Retrieve number with positions 0 onwards
- num_int = int(num[0:])
- ans += num_int
- print (ans)
Add Comment
Please, Sign In to add comment