Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from urllib.request import urlopen, urlretrieve
- from bs4 import BeautifulSoup
- url = " https://stepik.org/media/attachments/lesson/258944/New-York.html"
- response = urlopen(url)
- html = response.read().decode('utf-8')
- soup = BeautifulSoup(html)
- count = 0
- need = ["wikitable", "collapsible", "collapsed"]
- for link in soup.find_all('table'):
- if link.has_attr('class') and link.get('class') == need:
- count += 1
- if count == 2:
- for tr in link.find_all('tr'):
- for td in tr.find_all(['td', 'th']):
- print(td.text.strip(), end = ',')
- print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement