Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. from urllib.request import urlopen, urlretrieve
  2. from bs4 import BeautifulSoup
  3. url = " https://stepik.org/media/attachments/lesson/258944/New-York.html"
  4. response = urlopen(url)
  5. html = response.read().decode('utf-8')
  6. soup = BeautifulSoup(html)
  7. count = 0
  8. need = ["wikitable", "collapsible", "collapsed"]
  9. for link in soup.find_all('table'):
  10. if link.has_attr('class') and link.get('class') == need:
  11. count += 1
  12. if count == 2:
  13. for tr in link.find_all('tr'):
  14. for td in tr.find_all(['td', 'th']):
  15. print(td.text.strip(), end = ',')
  16. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement