Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3.  
  4. for index in range(1,28):
  5.     vhi_url = requests.get('https://www.star.nesdis.noaa.gov/smcd/emb/vci/VH/get_provinceData.php?country=USA&provinceID={}&year1=1981&year2=2017&type=Mean'.format(index))
  6.     soup = BeautifulSoup(vhi_url.text)
  7.     head = soup.body.tt.pre.getText().split('\n')[0].replace('year,week,, provinceID, SMN,SMT,VCI,TCI,VHI', 'year,week,SMN,SMT,VCI,TCI,VHI')
  8.     text = head + soup.body.tt.pre.getText().replace('year,week,, provinceID, SMN,SMT,VCI,TCI,VHI', '').replace(',', ' ').replace('  ', ' ').replace(' ',',')
  9.     output = open('provience-{}.csv'.format(index), 'w')
  10.     output.write(text)
  11.     output.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement