### Installation with pipenv Source: https://palewi.re/docs/savepagenow The package can be installed from the Python Package Index with one of Python’s installation tools. Here’s an example with `pipenv`. ```bash pipenv install savepagenow ``` -------------------------------- ### Develop CLI installation Source: https://palewi.re/docs/savepagenow The command-line interface is implemented using Click and setuptools. To install it locally for development inside your virtual environment, run the following installation command, as prescribed by the Click documentation. ```bash pip install --editable . ``` -------------------------------- ### Command-line usage Source: https://palewi.re/docs/savepagenow The Python library is also installed as a command-line interface. You can run it from your terminal like so: ```bash savepagenow https://example.com/ ``` -------------------------------- ### CLI Usage Help Source: https://palewi.re/docs/savepagenow The command has the same options as the Python API. ```bash Usage: savepagenow [OPTIONS] URL Archive the provided URL using archive.org's Wayback Machine. Raises a CachedPage exception if archive.org declines to conduct a new capture and returns a previous snapshot instead. Options: -ua, --user-agent TEXT User-Agent header for the web request -c, --accept-cache Accept and return cached URL -a, --authenticate Allows you to run saves with authentication --help Show this message and exit. ``` -------------------------------- ### Customize user agent from command line Source: https://palewi.re/docs/savepagenow And here’s how to do it from the command line: ```bash savepagenow http://www.example.com/ --user-agent "my user agent here" ``` -------------------------------- ### Import library Source: https://palewi.re/docs/savepagenow First import the library into your Python code. ```python import savepagenow ``` -------------------------------- ### Customize user agent in Python Source: https://palewi.re/docs/savepagenow Here’s how to do it in Python: ```python savepagenow.capture("http://www.example.com/", user_agent="my user agent here") ``` -------------------------------- ### Handle capture or cache result Source: https://palewi.re/docs/savepagenow There’s no accounting for taste but you could craft a line to handle that command like so: ```python url, captured = savepagenow.capture_or_cache("http://www.example.com/") ``` -------------------------------- ### Authenticated capture Source: https://palewi.re/docs/savepagenow Authenticated requests are allowed 6 captures per minute. To take advantage of this, you must register an account with archive.org and set your API credentials to the local environment variables `SAVEPAGENOW_ACCESS_KEY` and `SAVEPAGENOW_SECRET_KEY`. Then you can run `capture()` with the authenticate flag set to true like so: ```python savepagenow.capture(url, authenticate=True) ``` -------------------------------- ### Capture or cache method Source: https://palewi.re/docs/savepagenow You can craft your code to catch that exception yourself, or use the built-in `capture_or_cache` method, which will return the URL provided by archive.org along with a boolean indicating if it is a fresh capture (True) or from the cache (False). ```python savepagenow.capture_or_cache("http://www.example.com/") ("https://web.archive.org/web/20161019062832/http://www.example.com/", True) savepagenow.capture_or_cache("http://www.example.com/") ("https://web.archive.org/web/20161019062832/http://www.example.com/", False) ``` -------------------------------- ### Print archive URL Source: https://palewi.re/docs/savepagenow See where it’s stored. ```python print(archive_url) ``` -------------------------------- ### Capture a URL Source: https://palewi.re/docs/savepagenow Capture a URL. ```python archive_url = savepagenow.capture("http://www.example.com/") ``` -------------------------------- ### Cached pages exception handling Source: https://palewi.re/docs/savepagenow If a URL has been recently cached, archive.org may return the URL to that page rather than conduct a new capture. When that happens, the `capture` method will raise a `CachedPage` exception. This is likely happen if you request the same URL twice within a few seconds. ```python savepagenow.capture("http://www.example.com/") 'https://web.archive.org/web/20161019062637/http://www.example.com/' savepagenow.capture("http://www.example.com/") Traceback (most recent call last): File "", line 1, in File "savepagenow/__init__.py", line 36, in capture archive_url savepagenow.exceptions.CachedPage: archive.org returned a cached version of this page: https://web.archive.org/web/20161019062637/http://www.example.com/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.