-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathweather.py
44 lines (43 loc) · 819 Bytes
/
weather.py
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
import urllib2, re
response = urllib2.urlopen("http://www.nmc.cn/publish/forecast/ACQ/zhongqing.html")
data = response.read()
string = """div class="row wd">
<div class="label h3_wd">
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
<div>
.*?
</div>
</div> """
pattern = re.compile(string)
items = re.findall(pattern, data)
s = "".join(str(items).split())
s = s[1:len(s)-1]
print s
p = """<div>.*?</div>"""
pa= re.compile(p)
items = re.findall(pa, s)
for i in items:
print i
#print s.join(str(items).split())