-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path20151204Tempzol.py
78 lines (71 loc) · 2.02 KB
/
20151204Tempzol.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
import re
import urllib
import urllib2
import os
import time
from BeautifulSoup import BeautifulSoup, Tag
user_agent='Mozilla/5.0 (Windows NT 10.0; WOW64) '
headers={'User-Agent':user_agent}
url='http://detail.zol.com.cn/405/404011/param.shtml'
try:
request=urllib2.Request(url,headers=headers)
response=urllib2.urlopen(request)
html=response.read().decode('gbk')
except urllib2.URLError,e:
if hasattr(e,'reason'):
print u'连接失败的原因',e.reason
#print html
#pattern=u'<a href="(/\d.*?)".*?更多参数>></a>.*?</li>.*?</ul>'
#items=re.findall(pattern,html)
#print items
soup=BeautifulSoup(html)
print soup.find('title').getText()
print soup.find(attra={'var proName ='})
#print soup.find('head')
#print soup.head
#print soup.contents[0]
#print soup.contents[1]
#print soup.contents[2]
#get title
pattern=u'<h1.*?>(.*?)参数.*?</h1>'
title=re.search(pattern,html)
#print title
print title.group(1).strip()
#get frame
patternsheet=re.compile('<table>.*?<th>(.*?)</th>.*?</table>',re.S)
itemsheet=re.findall(patternsheet,html)
print len(itemsheet)
print itemsheet[0]
print itemsheet[1]
print itemsheet[2]
print itemsheet[3]
print itemsheet[4]
print itemsheet[5]
print itemsheet[6]
print itemsheet[7]
print itemsheet[8]
print itemsheet[9]
print itemsheet[10]
#get frame
patternsheet=re.compile('<table>(.*?)</table>',re.S)
itemsheet=re.findall(patternsheet,html)
#print itemsheet[0]
#print itemsheet[1]
#print itemsheet[2]
#print itemsheet[3]
#print itemsheet[4]
#print itemsheet[5]
#get time
patternone=re.compile('<li>.*?<span id=.*?>(.*?)</span>.*?<span id=.*?>(.*?)</span>.*?</li>',re.S)
itemsone=re.findall(patternone,itemsheet[0])
for itemone in itemsone:
havehref=re.search('a href.*?',itemone[1])
print u'------------\n'
print itemone[0]
if havehref:
newitemone=re.findall('<a href=.*?>(.*?)</a>',itemone[1])
for new in newitemone:
print new
else:
print itemone[1]