I can go to the Internet Wayback machine website and add a link to the site for the Wayback spider to scrape; is it possible to do this using their API as well? From what I've read you can only pull a list of the scraped sites.
2 Answers
Yes,
Please see the Save Page Now (SPN) API documentation here:
https://docs.google.com/document/d/19RJsRncGUw2qHqGGg9lqYZYf7KKXMDL1Mro5o1Qw6QI/
For questions please write to [email protected]
I could not really find the API specifications in link in @MarkGraham's answer but here is some sample code taken from my Stack Exchange Archivist userscript. It basically mimics what you do as a user when filling in the form here:
- a
POST
call tohttps://web.archive.org/save/
+ the URL you want to archive; parameters are theurl
andcapture_all=on
Only this step is required, but you can do more:
- the server returns some HTML / JavaScript with a call to
spn.watchJob
with the job ID, which you can use to monitor the progress - a GET call to
https://web.archive.org/save/status/
+ the job ID + some cache breaker will return a JSON with the status. If the status is 'success', it will also contain the URL to the snapshot.
function archive(link) {
console.log("Archiving: " + link);
// Call Wayback Machine
let archiveLink = "https://web.archive.org/save/" + link;
GM.xmlHttpRequest({
method: 'POST',
url: archiveLink,
data: $.param({
"url": link,
"capture_all": "on"
}),
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response) {
console.log(response.response);
let match = /spn.watchJob\("([^"]+)",/g.exec(response.response);
if (match == null) {
console.log("Could not determine job ID for " + archiveLink);
next(false);
return;
}
// Start monitoring archiving job
setTimeout(function () {
monitorArchivingJob(match[1]);
}, 2500);
},
onerror: function(response) {
console.log(["An error occurred while calling: " + archiveLink,
response.status, response.statusText, response.readyState,
response.responseHeaders, response.responseText, response.finalUrl].join("\n"));
next(false);
}
});
}
function monitorArchivingJob(jobID) {
// Fetch job status
let url = "https://web.archive.org/save/status/" + jobID + "?_t=" + Math.floor(Date.now() / 1000);
console.log(url);
GM.xmlHttpRequest({
method: 'GET',
url: url,
onload: function(response) {
let data = JSON.parse(response.response);
// Check status
if (data.status == "pending") {
setTimeout(function () {
monitorArchivingJob(jobID);
}, 2500);
} else if (data.status == "success") {
// Success!
let playbackURL = "https://web.archive.org/web/" + data.timestamp + "/" + data.original_url;
console.log("Saved: " + playbackURL);
next(true);
} else {
console.log("Failed to archive: " + url);
next(false);
}
},
onerror: function(response) {
console.log(["An error occurred while calling: " + url,
response.status, response.statusText, response.readyState,
response.responseHeaders, response.responseText, response.finalUrl].join("\n"));
next(false);
}
});
}