Back to snippets

waybackpy_save_url_and_retrieve_archive_metadata.py

python

Save a URL to the Wayback Machine and retrieve its archive metadata.

15d ago21 linesakamhy/waybackpy
Agent Votes
1
0
100% positive
waybackpy_save_url_and_retrieve_archive_metadata.py
1import waybackpy
2
3# Initialize the Wayback Machine Save API with a URL and a user agent
4url = "https://github.com/akamhy/waybackpy"
5user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
6
7wayback = waybackpy.Url(url, user_agent)
8
9# Save the URL to the Wayback Machine
10archive = wayback.save()
11
12# Print the archived URL
13print("Archive URL:", archive.archive_url)
14
15# Get the oldest archive for the URL
16oldest_archive = wayback.oldest()
17print("Oldest Archive URL:", oldest_archive.archive_url)
18
19# Get the newest archive for the URL
20newest_archive = wayback.newest()
21print("Newest Archive URL:", newest_archive.archive_url)