Skip to content
Snippets Groups Projects
Commit 70722f7e authored by Andreas's avatar Andreas
Browse files

Save Page Sample

parent 02c7aecd
No related branches found
No related tags found
2 merge requests!9Save Page sample,!5API Changes
%% Cell type:markdown id: tags:
%% Cell type:code id: tags:
``` python
import requests
import json
```
%% Cell type:markdown id: tags:
Create a WebarchivSession Object with convenience methods for easy access with your API-Key
%% Cell type:code id: tags:
``` python
from webarchiv import WebarchivSession
apikey = '2pm8i0hnmpcTK4Oj4CUeBoZd7vywrm4c'
w = WebarchivSession(apikey)
```
%% Cell type:raw id: tags:
request archiving a Webpage
%% Cell type:code id: tags:
``` python
response = w.savePage("http://www.onb.ac.at")
if response.status_code == 201:
print(response.json())
else:
print("Error ", response.status_code)
```
%% Output
{'nomination_id': 247, 'seed': 'http://www.onb.ac.at', 'nominationtype': 5}
%% Cell type:code id: tags:
``` python
```
......@@ -251,15 +251,30 @@ class WebarchivSession:
def getSnapshotUrl(self, seed, capture, onlysvg):
return self.api_path + 'snapshot?capture=' + capture + '&t=' + self.token + '&apikey=' + self.api_key + '&onlysvg=' + onlysvg + '&seed=' + seed;
def savePage(self, url):
self.connect()
r = requests.post(self.base_url.format('savepage'),
data='''{{
"apikey": "{api_key}",
"t": "{token}",
"url": "{url}"
}}'''.format(api_key=self.api_key, token=self.token, url=url),
headers={
'content-type': 'application/json',
'accept': 'application/ld+json'
}
)
return r;
if __name__ == '__main__':
# noinspection SpellCheckingInspection
w = WebarchivSession('2pm8i0hnmpcTK4Oj4CUeBoZd7vywrm4c')
# response = w.wayback_search("http://www.onb.ac.at")
# response = w.wayback_search("http://frauenhetz.jetzt")
response = w.histogram_search("Nationalbibliothek Prunksaal Schwarzenegger")
# response = w.wayback_search("x")
#response = w.histogram_search("Nationalbibliothek Prunksaal Schwarzenegger")
response = w.savePage("http://www.onb.ac.at")
if response.status_code == 200:
if response.status_code == 201:
print(response.json())
else:
print("Error ", response.status_code)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment