-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpage_parse.py
50 lines (40 loc) · 979 Bytes
/
webpage_parse.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
#coding=utf-8
"""
对抓取网页的解析
"""
import re
import urllib2
import log
import config_load
class WebpageParse(object):
"""
weppage parse
"""
def __init__(self):
self.logger=log.init_log("./log/mini_spider_log")
def get_target_urls(self, content):
"""
get target url list match the pattern
Args:
url_list:url list
pattern: the url pattern
Return:
url lists
"""
reg=r'(?<=href=).*?\.html'
urlgre=re.compile(reg)
urllists=list()
urllists =re.findall(urlgre, content)
#for urllist in urllists:
#urllist=urllist.replace('\'','')
#urllist = urllist.replace('\"', '')
#print urllist
return urllists
"""
url="http://pycm.baidu.com:8081/"
res=urllib2.urlopen(url)
content=res.read()
wp=WebpageParse()
#lists=list()
wp.get_target_urls(content)
"""