Skip to content

Instantly share code, notes, and snippets.

@msanatan
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msanatan/9d0eee0ce907fdd651e6 to your computer and use it in GitHub Desktop.
Save msanatan/9d0eee0ce907fdd651e6 to your computer and use it in GitHub Desktop.
Scraper for wholesale fish market prices in Trinidad and Tobago
from lxml import html
import requests
import time
date = time.strftime('%d-%m-%Y')
output = ''
try:
page = requests.get('http://www.namistt.com/')
except requests.exceptions.RequestException as e:
print 'Could not reach the website:'
raise e
tree = html.fromstring(page.text)
price_tables = tree.get_element_by_id('tbl')
print 'Retrieving table data'
for row in price_tables.findall('.//tr'):
row = [r.xpath('./text()')[0].strip() for r in row]
if row[2]:
print row
output += ','.join(row) + '\n'
f = open('NAMIS Wholesale Fish Market Prices {0}.csv'.format(date), 'w')
print 'Writing to file'
f.write(output)
f.close()
print 'Done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment