From f23df8a74781370b06590012d1c16772980345e2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Fri, 4 Oct 2019 09:38:42 -0400 Subject: [PATCH] test --- sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py b/sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py index fb2eb90..65e4210 100644 --- a/sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py +++ b/sopel_modules/SpiceBot_Core_Tools/HTTP_Codes.py @@ -16,6 +16,7 @@ from lxml import etree from lxml import html api_url = 'https://httpstatuses.com/' +basic_xpath = "/html/body/article/h1[1]/text()" @SpiceBot.prerun('module') @@ -52,8 +53,11 @@ def fetch_result(query): tree = html.fromstring(r.content) + title = tree.xpath((basic_xpath)) + return str(title) + try: - title = tree.xpath(('/html/body/article/p[1]')[0]) + title = tree.xpath((basic_xpath)) # if isinstance(title, list): # title = title[0] # title = str(title) @@ -63,15 +67,6 @@ def fetch_result(query): except Exception as e: title = None if title: - return title + return str(title) else: return "An Error Occured" - - return - - page = etree.HTML(r.content) - title = bleach.clean(etree.tostring(page.xpath('/html/body/article/h1[1]')[0]), tags=[], strip=True) - summary = bleach.clean( - re.sub('.*?<\/a>', '', etree.tostring(page.xpath('/html/body/article/p[1]')[0])), tags=[], - strip=True) - return "{title}: {summary} — {link}".format(title=title, summary=summary, link=url)