Implement --write-pages option (#736)

* Implement --write-pages option

* Fix long lines

* Fix file mode to binary

* Fix pattern for Windows compatibility
This commit is contained in:
Vrihub
2020-05-12 14:25:21 +02:00
committed by GitHub
parent fe224416bf
commit 4cc761c730
2 changed files with 17 additions and 0 deletions

View File

@@ -96,6 +96,17 @@ class Extractor():
(400 <= code < 429 or 431 <= code < 500):
if encoding:
response.encoding = encoding
if config.get((), "write_pages", False):
# Write the response content to a .dump file
# in the current directory.
# The file name is derived from the response
# url, replacing special characters with "_"
r = re.compile(r"[\\\\|/<>:\"?*&=#]+")
outfilename = r.sub('_', response.url) + '.dump'
with open(outfilename, 'wb') as outfile:
outfile.write(response.content)
return response
if notfound and code == 404:
raise exception.NotFoundError(notfound)