0
我使用的Ubuntu 12.04,当它返回一个URL,Python 2.7版如何使用的Xapian索引网页
我从给定的URL获取内容代码:
def get_page(url):
'''Gets the contents of a page from a given URL'''
try:
f = urllib.urlopen(url)
page = f.read()
f.close()
return page
except:
return ""
return ""
要过滤的内容通过get_page(url)
提供的页面:
def filterContents(content):
'''Filters the content from a page'''
filteredContent = ''
regex = re.compile('(?<!script)[>](?![\s\#\'-<]).+?[<]')
for words in regex.findall(content):
word_list = split_string(words, """ ,"!-.()<>[]{};:?!-=/_`&""")
for word in word_list:
filteredContent = filteredContent + word
return filteredContent
def split_string(source, splitlist):
return ''.join([ w if w not in splitlist else ' ' for w in source])
如何索引Xapian
的filteredContent
这样,当我询问,我得到的返回URLs
查询出现在?
谢谢你的时间和帮助。如何显示页面内容和URL? – VeilEclipse 2013-04-24 09:32:58
掌握Xapian的概念。例如,您可以在文档数据中放入任何您想要的东西;正确的处理方式取决于你的情况和你在做什么,所以我不能给出具体的建议。 – 2013-04-25 14:35:44