Guest User

Untitled

a guest
Dec 11th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. # 1. Import urllib and beautifulsoup
  2. from urllib.request import urlopen
  3. from bs4 import BeautifulSoup
  4. import ssl
  5.  
  6. # 2. Ignore SSL certificate errors
  7. ctx = ssl.create_default_context()
  8. ctx.check_hostname = False
  9. ctx.verify_mode = ssl.CERT_NONE
  10.  
  11. # 3. Read HTML with urllib's urlopen() method
  12. url = input('Enter - ')
  13. html = urlopen(url, context=ctx).read()
  14.  
  15. # 4. Parse HTML with BeautifulSoup's BeautifulSoup() method
  16. soup = BeautifulSoup(html, "html.parser")
  17.  
  18. # 5. Retrieve list of span tags
  19. tags = soup('span')
  20.  
  21. ans = 0
  22. # 6. Loop through to get numbers
  23. for tag in tags:
  24. num = tag.contents[0]
  25. # Retrieve number with positions 0 onwards
  26. num_int = int(num[0:])
  27. ans += num_int
  28. print (ans)
Add Comment
Please, Sign In to add comment