adding keiths changes from dev list

This commit is contained in:
Matt Burton 2009-07-16 15:11:24 +00:00
parent 3a5da5e6df
commit 1de4502a1a

View file

@ -32,20 +32,20 @@ function scrape(doc, url) {
var namespace = doc.documentElement.namespaceURI;
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
} : null;
var dataTags = new Object();
var tagsContent = new Array();
var fieldTitle;
var newItem = new Zotero.Item("book");
var headers = doc.evaluate('//td[2]/pre/b', doc, nsResolver, XPathResult.ANY_TYPE, null);
var xPathCount = doc.evaluate('count (//td[2]/pre/b)', doc, nsResolver, XPathResult.ANY_TYPE, null);
var contents = doc.evaluate('//td[2]/pre', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var headersArray = new Array();
var headers = doc.evaluate('//td[2]/pre/b', doc, nsResolver,XPathResult.ANY_TYPE, null);
var xPathCount = doc.evaluate('count (//td[2]/pre/b)', doc,nsResolver, XPathResult.ANY_TYPE, null);
var contents = doc.evaluate('//td[2]/pre', doc, nsResolver,XPathResult.ANY_TYPE, null).iterateNext().textContent;
var headersArray = new Array();
var oneHeader = '';
if (xPathCount.numberValue > 1) {
@ -56,25 +56,25 @@ function scrape(doc, url) {
} else {
oneHeader = (headers.iterateNext().textContent);
}
var contentsArray = new Array();
var j = 0;
if (oneHeader.length<1) {
for (var i = headersArray.length-1; i> -1; i--) {
for (var i = headersArray.length-1; i> -1; i--) {
var fieldIndex = contents.indexOf(headersArray[i]);
var shorten = headersArray[i].length;
contentsArray.push(contents.substr(fieldIndex));
contents = contents.substr(0, fieldIndex);
fieldTitle = headersArray[i].replace(/\s+/g, '');
dataTags[fieldTitle] = contentsArray[j].substr(shorten).replace(/^\s*|\s+$/g, '');
j++;
}
}
}
associateData (newItem, dataTags, "DEPOT", "repository");
associateData (newItem, dataTags, "REFERENCE", "callNumber");
@ -83,15 +83,12 @@ function scrape(doc, url) {
associateData (newItem, dataTags, "VOLUME_NO", "volume");
associateData (newItem, dataTags, "REMARKS", "extra");
associateData (newItem, dataTags, "SUMMARY", "abstractNote");
associateData (newItem, dataTags, "SOURCE", "series");
if (dataTags["DESCRIPTION"]) {
associateData (newItem, dataTags, "DESCRIPTION", "title");
} else {
newItem.title = "No Title Found";
newItem.title = "No Title Found";
}
newItem.url = doc.location.href;
newItem.complete();
}
@ -100,18 +97,18 @@ function doWeb(doc, url) {
var nsResolver = namespace ? function(prefix) {
if (prefix == 'x') return namespace; else return null;
} : null;
var articles = new Array();
if (detectWeb(doc, url) == "multiple") {
var items = new Object();
var titles = doc.evaluate('//td/a', doc, nsResolver, XPathResult.ANY_TYPE, null);
var lastLink;
var next_title;
while (next_title = titles.iterateNext()) {
if (!next_title.textContent.match(/^\d\d\d\d/) && !next_title.textContent.match(/\\/) && next_title.textContent.length>3 && next_title.textContent.match(/\w/)) {
Zotero.debug(next_title.textContent);
items[next_title.href] = next_title.textContent;