This commit is contained in:
deathbybandaid 2019-10-04 09:31:27 -04:00
parent 5ebdad391b
commit 6413ddf148

View File

@ -13,6 +13,8 @@ import requests
import bleach import bleach
from lxml import etree from lxml import etree
from lxml import html
api_url = 'https://httpstatuses.com/' api_url = 'https://httpstatuses.com/'
@ -49,6 +51,25 @@ def fetch_result(query):
return "HTTP error: " + e.message return "HTTP error: " + e.message
return "testing" return "testing"
tree = html.fromstring(r.content)
try:
title = tree.xpath(('/html/body/article/p[1]')[0])
# if isinstance(title, list):
# title = title[0]
# title = str(title)
# for r in (("u'", ""), ("['", ""), ("[", ""), ("']", ""), ("\\n", ""), ("\\t", "")):
# title = title.replace(*r)
# title = unicode_string_cleanup(title)
except Exception as e:
title = None
if title:
return title
else:
return "An Error Occured"
return
page = etree.HTML(r.content) page = etree.HTML(r.content)
title = bleach.clean(etree.tostring(page.xpath('/html/body/article/h1[1]')[0]), tags=[], strip=True) title = bleach.clean(etree.tostring(page.xpath('/html/body/article/h1[1]')[0]), tags=[], strip=True)
summary = bleach.clean( summary = bleach.clean(