A Python library that interfaces with the Internet Archive's Wayback Machine API. Archive pages and retrieve archived pages easily.
Project description
waybackpy
Waybackpy is a Python library that interfaces with the Internet Archive's Wayback Machine API. Archive pages and retrieve archived pages easily.
Table of contents
-
- As a python package
- Saving an url using save()
- Receiving the oldest archive for an URL Using oldest()
- Receiving the recent most/newest archive for an URL using newest()
- Receiving archive close to a specified year, month, day, hour, and minute using near()
- Get the content of webpage using get()
- Count total archives for an URL using total_archives()
- With CLI
- As a python package
Installation
Using pip:
pip install waybackpy
or direct from this repository using git.
pip install git+https://github.com/akamhy/waybackpy.git
Usage
As a python package
Capturing aka Saving an url using save()
import waybackpy
new_archive_url = waybackpy.Url(
url = "https://en.wikipedia.org/wiki/Multivariable_calculus",
user_agent = "Mozilla/5.0 (Windows NT 5.1; rv:40.0) Gecko/20100101 Firefox/40.0"
).save()
print(new_archive_url)
https://web.archive.org/web/20200504141153/https://github.com/akamhy/waybackpy
Try this out in your browser @ https://repl.it/@akamhy/WaybackPySaveExample
Receiving the oldest archive for an URL using oldest()
import waybackpy
oldest_archive_url = waybackpy.Url(
"https://www.google.com/",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:40.0) Gecko/20100101 Firefox/40.0"
).oldest()
print(oldest_archive_url)
http://web.archive.org/web/19981111184551/http://google.com:80/
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyOldestExample
Receiving the newest archive for an URL using newest()
import waybackpy
newest_archive_url = waybackpy.Url(
"https://www.facebook.com/",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:39.0) Gecko/20100101 Firefox/39.0"
).newest()
print(newest_archive_url)
https://web.archive.org/web/20200714013225/https://www.facebook.com/
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyNewestExample
Receiving archive close to a specified year, month, day, hour, and minute using near()
from waybackpy import Url
user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0"
github_url = "https://github.com/"
github_wayback_obj = Url(github_url, user_agent)
# Do not pad (don't use zeros in the month, year, day, minute, and hour arguments). e.g. For January, set month = 1 and not month = 01.
github_archive_near_2010 = github_wayback_obj.near(year=2010)
print(github_archive_near_2010)
https://web.archive.org/web/20100719134402/http://github.com/
github_archive_near_2011_may = github_wayback_obj.near(year=2011, month=5)
print(github_archive_near_2011_may)
https://web.archive.org/web/20110519185447/https://github.com/
github_archive_near_2015_january_26 = github_wayback_obj.near(
year=2015, month=1, day=26
)
print(github_archive_near_2015_january_26)
https://web.archive.org/web/20150127031159/https://github.com
github_archive_near_2018_4_july_9_2_am = github_wayback_obj.near(
year=2018, month=7, day=4, hour = 9, minute = 2
)
print(github_archive_near_2018_4_july_9_2_am)
https://web.archive.org/web/20180704090245/https://github.com/
The library doesn't supports seconds yet. You are encourged to create a PR ;)
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyNearExample
Get the content of webpage using get()
import waybackpy
google_url = "https://www.google.com/"
User_Agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36"
waybackpy_url_object = waybackpy.Url(google_url, User_Agent)
# If no argument is passed in get(), it gets the source of the Url used to create the object.
current_google_url_source = waybackpy_url_object.get()
print(current_google_url_source)
# The following chunk of code will force a new archive of google.com and get the source of the archived page.
# waybackpy_url_object.save() type is string.
google_newest_archive_source = waybackpy_url_object.get(
waybackpy_url_object.save()
)
print(google_newest_archive_source)
# waybackpy_url_object.oldest() type is str, it's oldest archive of google.com
google_oldest_archive_source = waybackpy_url_object.get(
waybackpy_url_object.oldest()
)
print(google_oldest_archive_source)
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyGetExample#main.py
Count total archives for an URL using total_archives()
import waybackpy
URL = "https://en.wikipedia.org/wiki/Python (programming language)"
UA = "Mozilla/5.0 (iPad; CPU OS 8_1_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B435 Safari/600.1.4"
archive_count = waybackpy.Url(
url=URL,
user_agent=UA
).total_archives()
print(archive_count) # total_archives() returns an int
2440
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyTotalArchivesExample
With the CLI
Save
$ waybackpy --url "https://en.wikipedia.org/wiki/Social_media" --user_agent "my-unique-user-agent" --save
https://web.archive.org/web/20200719062108/https://en.wikipedia.org/wiki/Social_media
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyBashSave
Oldest archive
$ waybackpy --url "https://en.wikipedia.org/wiki/SpaceX" --user_agent "my-unique-user-agent" --oldest
https://web.archive.org/web/20040803000845/http://en.wikipedia.org:80/wiki/SpaceX
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyBashOldest
Newest archive
$ waybackpy --url "https://en.wikipedia.org/wiki/YouTube" --user_agent "my-unique-user-agent" --newest
https://web.archive.org/web/20200606044708/https://en.wikipedia.org/wiki/YouTube
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyBashNewest
Total number of archives
$ waybackpy --url "https://en.wikipedia.org/wiki/Linux_kernel" --user_agent "my-unique-user-agent" --total
853
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyBashTotal
Archive near time
$ waybackpy --url facebook.com --user_agent "my-unique-user-agent" --near --year 2012 --month 5 --day 12
https://web.archive.org/web/20120512142515/https://www.facebook.com/
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyBashNear
Get the source code
$ waybackpy --url google.com --user_agent "my-unique-user-agent" --get url # Prints the source code of the url
$ waybackpy --url google.com --user_agent "my-unique-user-agent" --get oldest # Prints the source code of the oldest archive
$ waybackpy --url google.com --user_agent "my-unique-user-agent" --get newest # Prints the source code of the newest archive
$ waybackpy --url google.com --user_agent "my-unique-user-agent" --get save # Save a new archive on wayback machine then print the source code of this archive.
Try this out in your browser @ https://repl.it/@akamhy/WaybackPyBashGet
Tests
Dependency
- None, just python standard libraries (re, json, urllib, argparse and datetime). Both python 2 and 3 are supported :)
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file waybackpy-2.1.3.tar.gz.
File metadata
- Download URL: waybackpy-2.1.3.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44eb2276719f9a649981578dabff1063c5dec4b1c1e77b64d56ff6ad270b6df1
|
|
| MD5 |
3942d751f4673993951e3fb275acdd6b
|
|
| BLAKE2b-256 |
e6e330230cb2d9591a471b9a3dc6846ae3bafeacc61d6329b3057e4f8a490bb0
|
File details
Details for the file waybackpy-2.1.3-py3-none-any.whl.
File metadata
- Download URL: waybackpy-2.1.3-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdf2fc77626c30e74c6407665a0e9d1f984a5592a91abbd2236976c01a9e8b0d
|
|
| MD5 |
33d58f5b944302d774271cbeff74c7d3
|
|
| BLAKE2b-256 |
65ff4b17ddcd4a7fccf47d626d580c2267f0b60c8846a4481cefa7ebfbf40af3
|