The WaybackMachineCDXServerAPI (CDX API) is used to query the Wayback Machine's CDX server for historical snapshots of a URL. This is the recommended way to perform high-performance queries.
Initialization:
Pass the url, user_agent, and optionally start_timestamp and end_timestamp (as integers).
Methods:
oldest(): Returns the oldest available snapshot object.newest(): Returns the newest available snapshot object.near(year=..., month=..., day=..., hour=..., minute=..., wayback_machine_timestamp=..., unix_timestamp=...): Returns the snapshot closest to the specified time.snapshots(): A generator that yields snapshot objects for the specified range.
Snapshot Object Attributes:
archive_url: The full URL to the archived page.original: The original URL.urlkey: The URL key used by the archive.timestamp: The Wayback Machine timestamp string.datetime_timestamp: A datetime.datetime object of the snapshot.statuscode: The HTTP status code of the archived page.mimetype: The MIME type of the archived content.
from waybackpy import WaybackMachineCDXServerAPI
url = "https://pypi.org"
user_agent = "Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0"
cdx = WaybackMachineCDXServerAPI(url, user_agent, start_timestamp=2016, end_timestamp=2017)
for item in cdx.snapshots():
print(item.archive_url)