Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webarchive-api
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
labs-team
webarchive-api
Commits
70722f7e
Commit
70722f7e
authored
6 years ago
by
Andreas
Browse files
Options
Downloads
Patches
Plain Diff
Save Page Sample
parent
02c7aecd
No related branches found
No related tags found
2 merge requests
!9
Save Page sample
,
!5
API Changes
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
sample8.ipynb
+99
-0
99 additions, 0 deletions
sample8.ipynb
webarchiv.py
+18
-3
18 additions, 3 deletions
webarchiv.py
with
117 additions
and
3 deletions
sample8.ipynb
0 → 100644
+
99
−
0
View file @
70722f7e
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a WebarchivSession Object with convenience methods for easy access with your API-Key "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from webarchiv import WebarchivSession\n",
"\n",
"apikey = '2pm8i0hnmpcTK4Oj4CUeBoZd7vywrm4c'\n",
"w = WebarchivSession(apikey)\n"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": [
"request archiving a Webpage"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'nomination_id': 247, 'seed': 'http://www.onb.ac.at', 'nominationtype': 5}\n"
]
}
],
"source": [
"response = w.savePage(\"http://www.onb.ac.at\")\n",
"\n",
"if response.status_code == 201:\n",
" print(response.json())\n",
"else:\n",
" print(\"Error \", response.status_code)\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
%% 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
```
This diff is collapsed.
Click to expand it.
webarchiv.py
+
18
−
3
View file @
70722f7e
...
...
@@ -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
==
20
0
:
if
response
.
status_code
==
20
1
:
print
(
response
.
json
())
else
:
print
(
"
Error
"
,
response
.
status_code
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment