-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFetchDataFromHtml_saveExcel.py
More file actions
55 lines (46 loc) · 1.48 KB
/
FetchDataFromHtml_saveExcel.py
File metadata and controls
55 lines (46 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# coding=gbk
'''
Created on 2012-8-29
@author: Neal Chen (njugui@gmail.com)
'''
import urllib
import sys
import datetime
from xlwt import Workbook
import time
'if keywords in the line, get data from > to </'
def getdata(keywords, line):
data = ''
if keywords in line:
start = line.find('>',)
end = line.find('</', start)
data = line[start+1:end]
return data
return False
def FetchData():
book = Workbook(encoding='gbk')
sheet1 = book.add_sheet('Sheet 2')
i = 0
theday = datetime.date(2009,12,31)
while i < 100:
i += 1
theday = theday + datetime.timedelta(days = 1)
print theday
theday_str = str(theday)
sheet1.write(i,0,theday_str)
check_url = r'http://www.88888.com/date=' + theday_str
try:
checkfile = urllib.urlopen(check_url)
except Exception,e:
print e
return
type = sys.getfilesystemencoding()
for line in checkfile:
line = line.decode("UTF-8").encode(type)
date_west = getdata('date_west', line)
if date_west != False:
sheet1.write(i,1,date_west)
book.save('simple.xls')
print 'finish!'
if __name__ == '__main__':
FetchData()