From ffaacffac757a896c9414886447939886b640d16 Mon Sep 17 00:00:00 2001 From: kirby81 Date: Tue, 3 Oct 2023 11:10:24 +0200 Subject: [PATCH 1/2] Update v2.0.0 --- CHANGELOG.md | 11 +++++++++++ scrapingbee/__version__.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c031bcc --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +## [2.0.0](https://github.com/ScrapingBee/scrapingbee-python/compare/v1.2.0...v2.0.0) (2023-10-03) + +### Improvement + +- Properly url encode all params (Thanks to @tuky with [PR15](https://github.com/ScrapingBee/scrapingbee-python/pull/15)). + +### Breaking change + +- No need to url encode params anymore. diff --git a/scrapingbee/__version__.py b/scrapingbee/__version__.py index 58d478a..8c0d5d5 100644 --- a/scrapingbee/__version__.py +++ b/scrapingbee/__version__.py @@ -1 +1 @@ -__version__ = '1.2.0' +__version__ = "2.0.0" From 92ee09ddefc8efdcef0950cb5ce7b153a6f2f34b Mon Sep 17 00:00:00 2001 From: kirby81 Date: Tue, 3 Oct 2023 11:22:27 +0200 Subject: [PATCH 2/2] fix test --- tests/test_utils.py | 65 ++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 5ed3377..eae4712 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -4,67 +4,60 @@ process_headers, process_cookies, process_params, - get_scrapingbee_url + get_scrapingbee_url, ) def test_process_js_snippet(): - '''It should encode JavaScript code''' - output = process_js_snippet( - 'window.scrollTo(0, document.body.scrollHeight);') - assert output == \ - 'd2luZG93LnNjcm9sbFRvKDAsIGRvY3VtZW50LmJvZHkuc2Nyb2xsSGVpZ2h0KTs=' + """It should encode JavaScript code""" + output = process_js_snippet("window.scrollTo(0, document.body.scrollHeight);") + assert output == "d2luZG93LnNjcm9sbFRvKDAsIGRvY3VtZW50LmJvZHkuc2Nyb2xsSGVpZ2h0KTs=" def test_process_headers(): - '''It should add a Spb- prefix to header names''' - output = process_headers({'Accept-Language': 'En-US'}) + """It should add a Spb- prefix to header names""" + output = process_headers({"Accept-Language": "En-US"}) assert output == { - 'User-Agent': 'ScrapingBee-Python/1.2.0', - 'Spb-Accept-Language': 'En-US', + "User-Agent": "ScrapingBee-Python/2.0.0", + "Spb-Accept-Language": "En-US", } def test_process_cookies(): - '''It should format cookies to a string''' - output = process_cookies({ - 'name_1': 'value_1', - 'name_2': 'value_2', - }) - assert output == 'name_1=value_1;name_2=value_2' + """It should format cookies to a string""" + output = process_cookies( + { + "name_1": "value_1", + "name_2": "value_2", + } + ) + assert output == "name_1=value_1;name_2=value_2" def test_process_extract_rules(): - '''It should format extract_rules to a stringified JSON''' - output = process_json_stringify_param({ - 'title': '.title' - }, 'extract_rules') + """It should format extract_rules to a stringified JSON""" + output = process_json_stringify_param({"title": ".title"}, "extract_rules") assert output == '{"title": ".title"}' def test_process_js_scenario(): - '''It should format js_scenario to a stringified JSON''' - output = process_json_stringify_param({ - 'instructions': [ - {"click": "#buttonId"} - ] - }, 'js_scenario') + """It should format js_scenario to a stringified JSON""" + output = process_json_stringify_param({"instructions": [{"click": "#buttonId"}]}, "js_scenario") assert output == '{"instructions": [{"click": "#buttonId"}]}' def test_process_params(): - '''It should keep boolean parameters''' - output = process_params({'render_js': True}) - assert output == {'render_js': True} + """It should keep boolean parameters""" + output = process_params({"render_js": True}) + assert output == {"render_js": True} def test_get_scrapingbee_url(): - '''It should generate a url''' + """It should generate a url""" output = get_scrapingbee_url( - 'https://app.scrapingbee.com/api/v1/', - 'API_KEY', - 'https://httpbin.org', - {'render_js': True, 'wait_for': '#foo'} + "https://app.scrapingbee.com/api/v1/", "API_KEY", "https://httpbin.org", {"render_js": True, "wait_for": "#foo"} + ) + assert ( + output == "https://app.scrapingbee.com/api/v1/" + "?api_key=API_KEY&url=https%3A%2F%2Fhttpbin.org&render_js=True&wait_for=%23foo" ) - assert output == 'https://app.scrapingbee.com/api/v1/' \ - '?api_key=API_KEY&url=https%3A%2F%2Fhttpbin.org&render_js=True&wait_for=%23foo'