Chém gió

Chủ Nhật, 1 tháng 12, 2013

Update USD exchange rate every 30s

import urllib2
import threading
import time
from bs4 import BeautifulSoup
def scrap():
    response = urllib2.urlopen('http://www.vietcombank.com.vn/exchangerates/')
    html = response.read()
    soup = BeautifulSoup(html)
    for i in soup.findAll('td',{"class":"code"}):
        if i.contents[0] == 'USD':
            print "Sell "+ i.find_all_next()[1].text
            print "Buy "+ i.find_all_next()[3].text
#t = threading.Timer(5, scrap)
while True:
        scrap()
        time.sleep(30)