# waybackpy ![Internet Archive](https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Internet_Archive_logo_and_wordmark.svg/84px-Internet_Archive_logo_and_wordmark.svg.png) ![Wayback Machine](https://upload.wikimedia.org/wikipedia/commons/thumb/0/01/Wayback_Machine_logo_2010.svg/284px-Wayback_Machine_logo_2010.svg.png) The waybackpy is a python wrapper for [Internet Archive](https://en.wikipedia.org/wiki/Internet_Archive)'s [Wayback Machine](https://en.wikipedia.org/wiki/Wayback_Machine). Table of contents ================= * [Installation](#installation) * [Usage](#usage) * [Saving an url using save()](#capturing-aka-saving-an-url-using-save) * [Receiving the oldest archive for an URL Using oldest()](#receiving-the-oldest-archive-for-an-url-using-oldest) * [Receiving the recent most/newest archive for an URL using newest()](#receiving-the-newest-archive-for-an-url-using-newest) * [Receiving archive close to a specified year, month, day, hour, and minute using near()](#receiving-archive-close-to-a-specified-year-month-day-hour-and-minute-using-near) * [Get the content of webpage using get()](#get-the-content-of-webpage-using-get) * [Tests](#tests) * [Dependency](#dependency) * [License](#license) ## Installation Using [pip](https://en.wikipedia.org/wiki/Pip_(package_manager)): **pip install waybackpy** ## Usage #### Capturing aka Saving an url Using save() ```diff + waybackpy.save(url, UA=user_agent) ``` > url is mandatory. UA is not, but highly recommended. ```python import waybackpy # Capturing a new archive on Wayback machine. # Default user-agent (UA) is "waybackpy python package", if not specified in the call. archived_url = waybackpy.save("https://github.com/akamhy/waybackpy", UA = "Any-User-Agent") print(archived_url) ``` This should print something similar to the following archived URL: #### Receiving the oldest archive for an URL Using oldest() ```diff + waybackpy.oldest(url, UA=user_agent) ``` > url is mandatory. UA is not, but highly recommended. ```python import waybackpy # retrieving the oldest archive on Wayback machine. # Default user-agent (UA) is "waybackpy python package", if not specified in the call. oldest_archive = waybackpy.oldest("https://www.google.com/", UA = "Any-User-Agent") print(oldest_archive) ``` This returns the oldest available archive for . #### Receiving the newest archive for an URL using newest() ```diff + waybackpy.newest(url, UA=user_agent) ``` > url is mandatory. UA is not, but highly recommended. ```python import waybackpy # retrieving the newest archive on Wayback machine. # Default user-agent (UA) is "waybackpy python package", if not specified in the call. newest_archive = waybackpy.newest("https://www.microsoft.com/en-us", UA = "Any-User-Agent") print(newest_archive) ``` This returns the newest available archive for , something just like this: #### Receiving archive close to a specified year, month, day, hour, and minute using near() ```diff + waybackpy.near(url, year=2020, month=1, day=1, hour=1, minute=1, UA=user_agent) ``` > url is mandotory. year,month,day,hour and minute are optional arguments. UA is not mandotory, but higly recomended. ```python import waybackpy # retriving the the closest archive from a specified year. # Default user-agent (UA) is "waybackpy python package", if not specified in the call. # supported argumnets are year,month,day,hour and minute archive_near_year = waybackpy.near("https://www.facebook.com/", year=2010, UA ="Any-User-Agent") print(archive_near_year) ``` returns : ```waybackpy.near("https://www.facebook.com/", year=2010, month=1, UA ="Any-User-Agent")``` returns: ```waybackpy.near("https://www.oracle.com/index.html", year=2019, month=1, day=5, UA ="Any-User-Agent")``` returns: > Please note that if you only specify the year, the current month and day are default arguments for month and day respectively. Do not expect just putting the year parameter would return the archive closer to January but the current month you are using the package. If you are using it in July 2018 and let's say you use ```waybackpy.near("https://www.facebook.com/", year=2011, UA ="Any-User-Agent")``` then you would be returned the nearest archive to July 2011 and not January 2011. You need to specify the month "1" for January. > 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() ```diff + waybackpy.get(url, encoding="UTF-8", UA=user_agent) ``` > url is mandatory. UA is not, but highly recommended. encoding is detected automatically, don't specify unless necessary. ```python from waybackpy import get # retriving the webpage from any url including the archived urls. Don't need to import other libraies :) # Default user-agent (UA) is "waybackpy python package", if not specified in the call. # supported argumnets are url, encoding and UA webpage = get("https://example.com/", UA="User-Agent") print(webpage) ```
Output of the above code

###### The source code for ! As no encoding was provided, it was auto identified. ```html Example Domain

Example Domain

This domain is for use in illustrative examples in documents. You may use this domain in literature without prior coordination or asking for permission.

More information...

```

## Dependency * None, just python standard libraries. Both python 2 and 3 are supported :) ## License [MIT License](LICENSE)