Save Page Now

repository·main·Indexed 42 days ago

https://github.com/palewire/savepagenow

A Python library and CLI tool for saving web pages to the Internet Archive. It provides the capture() and capture_or_cache() methods to request archives of URLs, supports authentication via SAVEPAGENOW_ACCESS_KEY and SAVEPAGENOW_SECRET_KEY to increase capture limits, and allows customization of the User-Agent header.

Tokens
989
Snippets
8
Records
8
Agent score
2%

What's inside Save Page Now

  1. Customize the User-Agent

    main

    By default, savepagenow uses the user agent "savepagenow (https://github.com/pastpages/savepagenow)". You can override this in both the Python API and the CLI.

    Python:

    savepagenow.capture("http://www.example.com/", user_agent="my user agent here")

    CLI:

    savepagenow http://www.example.com/ --user-agent "my user agent here"
  2. Authenticate requests to increase capture limits

    main

    By default, anonymous requests are limited to 3 captures per minute. Authenticated requests allow 6 captures per minute.

    To authenticate:

    1. Register an account at archive.org.
    2. Set your API credentials as local environment variables:
      • SAVEPAGENOW_ACCESS_KEY
      • SAVEPAGENOW_SECRET_KEY
    3. Call capture() with authenticate=True.
    savepagenow.capture(url, authenticate=True)
  3. Handle cached pages and the CachedPage exception

    main

    If archive.org returns an existing snapshot instead of performing a new capture, the capture() method raises a savepagenow.exceptions.CachedPage exception.

    To avoid handling exceptions, use capture_or_cache(). This method returns a tuple containing the archive URL and a boolean: True if it was a fresh capture, or False if it was retrieved from the cache.

    # Using capture_or_cache to avoid exceptions
    url, captured = savepagenow.capture_or_cache("http://www.example.com/")
    # url: the archive URL
    # captured: True if fresh, False if from cache
  4. Use savepagenow in Python

    main

    Import the library and use the capture() method to request a new archive of a URL. The method returns the URL of the archived page on archive.org.

    import savepagenow
    
    # Capture a URL
    archive_url = savepagenow.capture("http://www.example.com/")
    print(archive_url)
  5. Reference: savepagenow CLI options

    main

    The following options are available for the savepagenow command:

    • -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.
    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.