Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from bs4 import BeautifulSoup
  3. import requests
  4.  
  5. r = requests.get('http://www.cwb.gov.tw/V7/observe/rainfall/A136.htm')
  6. soup = BeautifulSoup(r.text, 'html.parser')
  7.  
  8. data = []
  9. table = soup.find('table', attrs={'class':'tablesorter'})
  10. table_body = table.find('tbody')
  11.  
  12. rows = table_body.find_all('tr')
  13. for row in rows:
  14.     cols = row.find_all('td')
  15.     cols = [ele.text.strip() for ele in cols]
  16.     data.append([ele for ele in cols if ele]) # Get rid of empty values
  17. print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement