From c79b3bfafd769ca678c5360e1d4c4a356e657ddf Mon Sep 17 00:00:00 2001 From: simon987 Date: Mon, 5 Apr 2021 19:17:27 -0400 Subject: [PATCH] Add get_soup() --- hexlib/web.py | 7 +++++++ setup.py | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hexlib/web.py b/hexlib/web.py index 6eca62e..1624df7 100644 --- a/hexlib/web.py +++ b/hexlib/web.py @@ -5,6 +5,7 @@ from datetime import datetime from base64 import b64encode, b64decode from http.cookiejar import Cookie from time import time +from bs4 import BeautifulSoup import requests import orjson as json @@ -171,3 +172,9 @@ class Web: if self._logger and r is not None: self._logger.debug(self._format_url("GET", url, kwargs, r) + " %.2fs" % (time() - time_start)) return r + + def get_soup(self, url, **kwargs): + r = self.get(url, **kwargs) + if not r: + return None + return BeautifulSoup(r.content, "html.parser") diff --git a/setup.py b/setup.py index 864d934..4545659 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="hexlib", - version="1.33", + version="1.34", description="Misc utility methods", author="simon987", author_email="me@simon987.net", @@ -13,6 +13,6 @@ setup( ]}, install_requires=[ "ImageHash", "influxdb", "siphash", "python-dateutil", "redis", "orjson", "zstandard", - "u-msgpack-python", "psycopg2-binary", "fake-useragent" + "u-msgpack-python", "psycopg2-binary", "fake-useragent", "bs4" ] )