From f23ccbfcb5019a291045b5eb61054c695e107d9c Mon Sep 17 00:00:00 2001 From: Xiao Tan Date: Thu, 21 Feb 2019 13:48:39 +0800 Subject: [PATCH 1/2] fix: fstring formatted with bytes --- requests_html.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requests_html.py b/requests_html.py index eb27eba..a6c80e8 100644 --- a/requests_html.py +++ b/requests_html.py @@ -416,9 +416,9 @@ class HTML(BaseParser): if isinstance(html, str): html = html.encode(DEFAULT_ENCODING) + pq = PyQuery(html) super(HTML, self).__init__( - # Convert unicode HTML to bytes. - element=PyQuery(html)('html') or PyQuery(f'{html}')('html'), + element=pq('html') or pq.wrapAll('')('html'), html=html, url=url, default_encoding=default_encoding From 9d78a005742300bf10f7765310623a98f036939f Mon Sep 17 00:00:00 2001 From: Xiao Tan Date: Fri, 22 Feb 2019 14:15:19 +0800 Subject: [PATCH 2/2] test: HTML parser --- tests/test_requests_html.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test_requests_html.py b/tests/test_requests_html.py index 05c2bf7..2aaee23 100644 --- a/tests/test_requests_html.py +++ b/tests/test_requests_html.py @@ -173,6 +173,15 @@ def test_absolute_links(url, link, expected): assert html.absolute_links.pop() == expected +@pytest.mark.parser +def test_parser(): + doc = """httpbin.org\n""" + html = HTML(html=doc) + + assert html.find('html') + assert html.element('a').text().strip() == 'httpbin.org' + + @pytest.mark.render def test_render(): r = get()