# -*- coding: utf-8 -*-
class TaipeiBike:
url = "http://data.kaohsiung.gov.tw/Opendata/DownLoad.aspx?Type=2&CaseNo1=AU&CaseNo2=1&FileType=2&Lang=C"
def __init__(self):
import os
self.currentPath = os.getcwd()
def Init(self):
import urllib.request
self.data = urllib.request.urlopen(self.url)
self.content = self.data.read().decode('utf-8')
self.data.close()
def Output(self):
import io
with open(self.currentPath + "/test.txt", "w") as sw:
sw.write(self.content)
sw.flush()
sw.close()
tb = TaipeiBike()
tb.Init()
tb.Output()
參考資料:
http://docs.python.org/3.3/library/os.html
http://docs.python.org/3.3/library/urllib.html
http://docs.python.org/3.3/library/urllib.request.html#module-urllib.request
http://docs.python.org/3.3/library/urllib.request.html#urllib.request.urlopen
http://docs.python.org/3.3/library/io.html
http://docs.python.org/3.3/library/io.html#text-i-o
