scrape-cli 1.3.3__tar.gz → 1.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/PKG-INFO +3 -1
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/pyproject.toml +5 -1
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli/__init__.py +1 -1
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli/scrape.py +16 -15
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli.egg-info/PKG-INFO +3 -1
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli.egg-info/entry_points.txt +1 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli.egg-info/requires.txt +3 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/tests/test_scrape.py +49 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/README.md +0 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli.egg-info/SOURCES.txt +0 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli.egg-info/dependency_links.txt +0 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/scrape_cli.egg-info/top_level.txt +0 -0
- {scrape_cli-1.3.3 → scrape_cli-1.3.5}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scrape_cli
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.5
|
|
4
4
|
Summary: It's a command-line tool to extract HTML elements using an XPath query or CSS3 selector.
|
|
5
5
|
Author-email: Andrea Borruso <aborruso@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/aborruso/scrape-cli
|
|
@@ -12,6 +12,8 @@ Requires-Dist: cssselect
|
|
|
12
12
|
Requires-Dist: lxml
|
|
13
13
|
Requires-Dist: requests
|
|
14
14
|
Requires-Dist: xmltodict
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest; extra == "dev"
|
|
15
17
|
|
|
16
18
|
[](https://pypi.org/project/scrape-cli/)
|
|
17
19
|
[](https://pypi.org/project/scrape-cli/)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scrape_cli"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.5"
|
|
8
8
|
description = "It's a command-line tool to extract HTML elements using an XPath query or CSS3 selector."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
authors = [
|
|
@@ -22,11 +22,15 @@ dependencies = [
|
|
|
22
22
|
"xmltodict"
|
|
23
23
|
]
|
|
24
24
|
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = ["pytest"]
|
|
27
|
+
|
|
25
28
|
[project.urls]
|
|
26
29
|
Homepage = "https://github.com/aborruso/scrape-cli"
|
|
27
30
|
|
|
28
31
|
[project.scripts]
|
|
29
32
|
scrape = "scrape_cli.scrape:main"
|
|
33
|
+
scrape-cli = "scrape_cli.scrape:main"
|
|
30
34
|
|
|
31
35
|
[tool.setuptools.packages.find]
|
|
32
36
|
where = ["."]
|
|
@@ -162,8 +162,8 @@ notes:
|
|
|
162
162
|
- -j fails with exit 1 on attribute names that are not valid XML, such as
|
|
163
163
|
@click or :bind. Use -e without -j on those pages.
|
|
164
164
|
- URLs: 30 s timeout, HTTP errors (4xx, 5xx) exit 1.
|
|
165
|
-
- Charset: from the meta tag, otherwise UTF-8.
|
|
166
|
-
|
|
165
|
+
- Charset: from the meta tag, otherwise UTF-8. If the bytes are not valid
|
|
166
|
+
UTF-8: Windows-1252, then ISO-8859-1. Other encodings need the meta tag.
|
|
167
167
|
'''
|
|
168
168
|
)
|
|
169
169
|
|
|
@@ -299,19 +299,20 @@ notes:
|
|
|
299
299
|
# If detected charset fails, fall back to default behavior
|
|
300
300
|
pass
|
|
301
301
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
302
|
+
if args.rawinput:
|
|
303
|
+
# XML declares its own encoding: leave the bytes to the parser
|
|
304
|
+
document = etree.fromstring(inp)
|
|
305
|
+
else:
|
|
306
|
+
# The recovering parser never fails on bad bytes, so check them here
|
|
307
|
+
try:
|
|
308
|
+
inp.decode('utf-8')
|
|
309
|
+
except UnicodeDecodeError:
|
|
310
|
+
# cp1252 rejects five undefined bytes, iso-8859-1 accepts them all
|
|
311
|
+
try:
|
|
312
|
+
inp = inp.decode('cp1252').encode('utf-8')
|
|
313
|
+
except UnicodeDecodeError:
|
|
314
|
+
inp = inp.decode('iso-8859-1').encode('utf-8')
|
|
315
|
+
document = etree.fromstring(inp, html_parser)
|
|
315
316
|
except (etree.XMLSyntaxError, UnicodeDecodeError) as e:
|
|
316
317
|
# Print an error in case of syntax issues in the HTML
|
|
317
318
|
print(f"Error parsing HTML: {e}", file=sys.stderr)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scrape_cli
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.5
|
|
4
4
|
Summary: It's a command-line tool to extract HTML elements using an XPath query or CSS3 selector.
|
|
5
5
|
Author-email: Andrea Borruso <aborruso@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/aborruso/scrape-cli
|
|
@@ -12,6 +12,8 @@ Requires-Dist: cssselect
|
|
|
12
12
|
Requires-Dist: lxml
|
|
13
13
|
Requires-Dist: requests
|
|
14
14
|
Requires-Dist: xmltodict
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: pytest; extra == "dev"
|
|
15
17
|
|
|
16
18
|
[](https://pypi.org/project/scrape-cli/)
|
|
17
19
|
[](https://pypi.org/project/scrape-cli/)
|
|
@@ -107,6 +107,55 @@ def test_encoding_meta_charset_iso_8859_1(tmp_path):
|
|
|
107
107
|
assert result.stdout.strip() == "Perché"
|
|
108
108
|
|
|
109
109
|
|
|
110
|
+
def test_encoding_falls_back_to_iso_8859_1_without_meta(tmp_path):
|
|
111
|
+
html_file = tmp_path / "latin1.html"
|
|
112
|
+
html_file.write_bytes("<h1>Caffè</h1>".encode("iso-8859-1"))
|
|
113
|
+
|
|
114
|
+
result = run_scrape(str(html_file), "-e", "string(//h1)")
|
|
115
|
+
|
|
116
|
+
assert result.returncode == 0
|
|
117
|
+
assert result.stdout == "Caffè\n"
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_encoding_windows_1252_without_meta(tmp_path):
|
|
121
|
+
html_file = tmp_path / "cp1252.html"
|
|
122
|
+
html_file.write_bytes("<h1>Caffè € ’</h1>".encode("cp1252"))
|
|
123
|
+
|
|
124
|
+
result = run_scrape(str(html_file), "-e", "string(//h1)")
|
|
125
|
+
|
|
126
|
+
assert result.returncode == 0
|
|
127
|
+
assert result.stdout == "Caffè € ’\n"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_encoding_bytes_undefined_in_windows_1252_fall_back_to_iso_8859_1(tmp_path):
|
|
131
|
+
html_file = tmp_path / "undefined.html"
|
|
132
|
+
html_file.write_bytes(b"<h1>Caff\xe8 \x81</h1>")
|
|
133
|
+
|
|
134
|
+
result = run_scrape(str(html_file), "-e", "string(//h1)")
|
|
135
|
+
|
|
136
|
+
assert result.returncode == 0
|
|
137
|
+
assert result.stdout.startswith("Caffè")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_encoding_utf8_without_meta_is_not_converted(tmp_path):
|
|
141
|
+
html_file = tmp_path / "utf8.html"
|
|
142
|
+
html_file.write_bytes("<h1>Caffè €</h1>".encode("utf-8"))
|
|
143
|
+
|
|
144
|
+
result = run_scrape(str(html_file), "-e", "string(//h1)")
|
|
145
|
+
|
|
146
|
+
assert result.stdout == "Caffè €\n"
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_rawinput_keeps_the_encoding_declared_by_the_xml(tmp_path):
|
|
150
|
+
xml_file = tmp_path / "latin1.xml"
|
|
151
|
+
xml_file.write_bytes('<?xml version="1.0" encoding="iso-8859-1"?><a>Caffè</a>'.encode("iso-8859-1"))
|
|
152
|
+
|
|
153
|
+
result = run_scrape(str(xml_file), "-r", "-e", "string(//a)")
|
|
154
|
+
|
|
155
|
+
assert result.returncode == 0
|
|
156
|
+
assert result.stdout == "Caffè\n"
|
|
157
|
+
|
|
158
|
+
|
|
110
159
|
def test_argument_extracts_attribute_value():
|
|
111
160
|
result = run_scrape(str(TEST_HTML), "-e", "//a[@class='external-link']", "-a", "href")
|
|
112
161
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|