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