Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from bs4 import BeautifulSoup
- import requests
- r = requests.get('http://www.cwb.gov.tw/V7/observe/rainfall/A136.htm')
- soup = BeautifulSoup(r.text, 'html.parser')
- data = []
- table = soup.find('table', attrs={'class':'tablesorter'})
- table_body = table.find('tbody')
- rows = table_body.find_all('tr')
- for row in rows:
- cols = row.find_all('td')
- cols = [ele.text.strip() for ele in cols]
- data.append([ele for ele in cols if ele]) # Get rid of empty values
- print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement