parent
e5a82ff1f4
commit
78cea10ead
|
@ -636,7 +636,7 @@ def cgi_file_handler(environ, start_response, app):
|
||||||
return app(environ, start_response)
|
return app(environ, start_response)
|
||||||
|
|
||||||
|
|
||||||
def cgi_page(environ, start_response):
|
def cgi_get(environ, start_response):
|
||||||
url, options = cgi_parse_environ(environ)
|
url, options = cgi_parse_environ(environ)
|
||||||
|
|
||||||
# get page
|
# get page
|
||||||
|
@ -648,6 +648,7 @@ def cgi_page(environ, start_response):
|
||||||
data, con, contenttype, encoding = crawler.adv_get(url=url)
|
data, con, contenttype, encoding = crawler.adv_get(url=url)
|
||||||
|
|
||||||
if contenttype in ['text/html', 'application/xhtml+xml', 'application/xml']:
|
if contenttype in ['text/html', 'application/xhtml+xml', 'application/xml']:
|
||||||
|
if options.get == 'page':
|
||||||
html = readabilite.parse(data, encoding=encoding)
|
html = readabilite.parse(data, encoding=encoding)
|
||||||
html.make_links_absolute(con.geturl())
|
html.make_links_absolute(con.geturl())
|
||||||
|
|
||||||
|
@ -659,17 +660,23 @@ def cgi_page(environ, start_response):
|
||||||
|
|
||||||
output = lxml.etree.tostring(html.getroottree(), encoding='utf-8')
|
output = lxml.etree.tostring(html.getroottree(), encoding='utf-8')
|
||||||
|
|
||||||
|
elif options.get == 'article':
|
||||||
|
output = readabilite.get_article(data, url=con.geturl(), encoding=encoding)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
output = None
|
raise MorssException('no :get option passed')
|
||||||
|
|
||||||
|
else:
|
||||||
|
output = data
|
||||||
|
|
||||||
# return html page
|
# return html page
|
||||||
headers = {'status': '200 OK', 'content-type': 'text/html'}
|
headers = {'status': '200 OK', 'content-type': 'text/html; charset=utf-8'}
|
||||||
start_response(headers['status'], list(headers.items()))
|
start_response(headers['status'], list(headers.items()))
|
||||||
return [output]
|
return [output]
|
||||||
|
|
||||||
|
|
||||||
dispatch_table = {
|
dispatch_table = {
|
||||||
'getpage': cgi_page
|
'get': cgi_get,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue