-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchengine.py
66 lines (55 loc) · 1.52 KB
/
searchengine.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
# -*- coding:UTF-8 -*-
import urllib
class crawler:
# 初始化, 并传入 数据库名称
def __init__(self,dbname):
pass
def __del__(self):
pass
def dbcommit(self):
pass
# 获取 条目的id,如果条目不在,就加入数据库中
def getentryid(self,table,field,value,createnew=True):
return None
# 为每个网页建立索引
def addtoindex(self,url,soup):
print 'Indexing %s' % url
# 从网页中提取网页
def gettextonly(self,soup):
return None
# 对非空白字符进行分词处理
def separatewords(self,text):
return None
# 已建立索引,则返回 True
def isindexed(self,url):
return False
# 添加关联两个网页的链接
def addlinkref(self,urlFrom,urlTo,linkText):
pass
# 从某网页进行广度搜索,直至某一给定深度
def crwal(self,pages,depth=2):
pass
# 创建数据库
def createindextable(self):
pass
# 下载文件,url 地址, fname 保存的文件名
def download_file(url,fname):
urllib.urlretrieve(url,fname)
def open(url):
import urllib2
c = urllib2.urlopen(url)
contents = c.read()
return contents.decode('gbk','ignore')
def test_twill(url):
from twill import get_browser
b = get_browser()
b.go(url)
b.showforms()
pass
def main():
url = "http://202.114.74.198"
contents = open(url)
print contents
#test_twill(url)
if __name__ == "__main__":
main()