Files
waybackpy/README.md
2020-07-19 15:34:43 +05:30

7.0 KiB

waybackpy

Build Status Downloads Release Codacy Badge License: MIT Maintainability CodeFactor made-with-python pypi PyPI - Python Version Maintenance codecov contributions welcome

Internet Archive Wayback Machine

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

Installation

Using pip:

pip install waybackpy

Usage

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/repls/CompassionateRemoteOrigin#main.py

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/repls/MixedSuperDimensions#main.py

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/repls/OblongMiniInteger#main.py

Receiving archive close to a specified year, month, day, hour, and minute using near()

import waybackpy
# retriving the the closest archive from a specified year.
# supported argumnets are year,month,day,hour and minute
target_url = waybackpy.Url(https://www.facebook.com/", "Any-User-Agent")
archive_near_year = target_url.near(year=2010)
print(archive_near_year)

returns : http://web.archive.org/web/20100504071154/http://www.facebook.com/

Please note that if you only specify the year, the current month and day are default arguments for month and day respectively. Just putting the year parameter would not return the archive closer to January but the current month you are using the package. You need to specify the month "1" for January , 2 for february and so on.

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.

Get the content of webpage using get()

import waybackpy
# retriving the webpage from any url including the archived urls. Don't need to import other libraies :)
# supported argumnets encoding and user_agent
target = waybackpy.Url("google.com", "any-user_agent")
oldest_url = target.oldest()
webpage = target.get(oldest_url) # We are getting the source of oldest archive of google.com.
print(webpage)

This should print the source code for oldest archive of google.com. If no URL is passed in get() then it should retrive the source code of google.com and not any archive.

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/repls/DigitalUnconsciousNumbers#main.py

Tests

Dependency

  • None, just python standard libraries (re, json, urllib and datetime). Both python 2 and 3 are supported :)

License

MIT License