Adding Sylvain's 15mar10 changes.
This commit is contained in:
parent
1caa7ac359
commit
466cf794e1
1 changed files with 92 additions and 72 deletions
|
@ -8,7 +8,7 @@
|
|||
"maxVersion":"",
|
||||
"priority":100,
|
||||
"inRepository":true,
|
||||
"lastUpdated":"2009-10-08 17:40:00"
|
||||
"lastUpdated":"2010-02-20 10:40:00"
|
||||
}
|
||||
|
||||
function detectWeb(doc, url) {
|
||||
|
@ -35,9 +35,9 @@ function detectWeb(doc, url) {
|
|||
}
|
||||
else if (indexArk == 0)
|
||||
{
|
||||
var iconxpath = '//div[@id="Infos"]/img';
|
||||
if (elt = doc.evaluate(iconxpath, doc, nsResolver,
|
||||
XPathResult.ANY_TYPE, null).iterateNext()) {
|
||||
var iconxpath = '//div[@class="contenu1"]/img';
|
||||
if (elt = doc.evaluate(iconxpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext())
|
||||
{
|
||||
var icon = elt.getAttribute('src');
|
||||
return getDoctypeGallica(icon);
|
||||
}
|
||||
|
@ -45,9 +45,9 @@ XPathResult.ANY_TYPE, null).iterateNext()) {
|
|||
// For some biblio, the icon picture is located in another div ...
|
||||
var iconxpath = '//div[@class="titrePeriodiqueGauche"]/img';
|
||||
if (elt = doc.evaluate(iconxpath, doc, nsResolver,
|
||||
XPathResult.ANY_TYPE, null).iterateNext()) {
|
||||
XPathResult.ANY_TYPE, null).iterateNext())
|
||||
{
|
||||
var icon = elt.getAttribute('src');
|
||||
|
||||
return getDoctypeGallica(icon);
|
||||
}
|
||||
}
|
||||
|
@ -62,19 +62,29 @@ function getDoctypeGallica(img)
|
|||
{
|
||||
var iconname = img.substring(img.lastIndexOf('/') + 1);
|
||||
|
||||
if ( (iconname =='doc_livre_ocr.png') || (iconname == 'doc_livre.png') )
|
||||
if (iconname =='livre_a.png')
|
||||
{
|
||||
return "book";
|
||||
}
|
||||
else if (iconname == 'doc_carte.png')
|
||||
else if (iconname == 'carte.png')
|
||||
{
|
||||
return "map";
|
||||
}
|
||||
else if (iconname == 'doc_image.png')
|
||||
else if (iconname == 'images.png')
|
||||
{
|
||||
return "artwork";
|
||||
}
|
||||
else if ( (iconname == 'doc_periodique.png') || (iconname == 'doc_perio_vol_ocr.png') )
|
||||
else if (iconname == 'docsonore.png')
|
||||
{
|
||||
return "audioRecording";
|
||||
}
|
||||
else if (iconname == 'musiquenotee.png')
|
||||
{
|
||||
// This icon is for Sheet music type. But no Zotero type matches
|
||||
// as of today (2010-02)
|
||||
return "book";
|
||||
}
|
||||
else if ( (iconname == 'picto_type_document1.png') || (iconname == 'perio_vol_ocr.png') )
|
||||
{
|
||||
return "book";
|
||||
}
|
||||
|
@ -95,23 +105,18 @@ function doWeb(doc, url) {
|
|||
if (detectWeb(doc, url) == "multiple")
|
||||
{
|
||||
var availableItems = new Array();
|
||||
var xpath = '//td[@class="ResultatsRechercheInfos"]/a';
|
||||
var xpath = '//div[@class="resultats_line"]';
|
||||
|
||||
var elmts = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);
|
||||
var elmt = elmts.iterateNext();
|
||||
|
||||
var itemsId = new Array();
|
||||
|
||||
var i = 0;
|
||||
var i = 1;
|
||||
do {
|
||||
var id = doc.evaluate('../../..//a[@id]', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
// This id looks like idN00000. We need the information after id to get the informations about
|
||||
// the title. We need to store it in an array, we leave the starting id.
|
||||
var cleanId = id.getAttribute('id').substring(2);
|
||||
itemsId[i] = cleanId;
|
||||
|
||||
var searchTitle = elmt.textContent;
|
||||
availableItems[i] = searchTitle;
|
||||
var id = doc.evaluate('div[@class="resultat_id"]', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
|
||||
var this_result = doc.evaluate('div[@class="resultat_desc"]/div[@class="titre"]/a', elmt, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
availableItems[i] = Zotero.Utilities.cleanTags(this_result.getAttribute('title'));
|
||||
|
||||
i++;
|
||||
} while (elmt = elmts.iterateNext());
|
||||
|
@ -122,25 +127,33 @@ function doWeb(doc, url) {
|
|||
// All informations are available on search result page. We don't need to query
|
||||
// every subpage with scrape. We'are going to call the special Gallica scrape function
|
||||
// This function (scrapeGallica) is reused in scrape.
|
||||
var fullpath = '//div[@id="noticeComplete' + itemsId[i] + '"]/div';
|
||||
var detail = doc.evaluate(fullpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
Zotero.debug(itemsId[i]);
|
||||
var iconType = doc.evaluate('//a[@id="id' + itemsId[i] + '"]/..//span[@class="typedoc"]/img', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
var fullpath = '//div[@class="resultats_line"][' + i + ']';
|
||||
|
||||
var item_element = doc.evaluate(fullpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
if (item_element != undefined)
|
||||
{
|
||||
var detail = doc.evaluate('.//div[@class="notice"]', item_element, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
|
||||
var iconType = doc.evaluate('.//div[@class="picto"]/img', item_element, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
var docType = getDoctypeGallica(iconType.getAttribute('src'));
|
||||
Zotero.debug( itemsId[i]);
|
||||
scrapeGallica(doc, nsResolver, detail, docType);
|
||||
|
||||
var docUrl = doc.evaluate('.//div[@class="liens"]/a', item_element, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
docUrl = docUrl.getAttribute("href");
|
||||
|
||||
scrapeGallica(doc, nsResolver, detail, docType, docUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var docType = detectWeb(doc, url);
|
||||
var xpath = '//div[@id="Popup1"]/div[@class="data"]';
|
||||
var xpath = '//div[@class="notice"]';
|
||||
var detail = doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext();
|
||||
scrapeGallica(doc, nsResolver, detail, docType);
|
||||
scrapeGallica(doc, nsResolver, detail, docType, "");
|
||||
}
|
||||
}
|
||||
|
||||
function scrapeGallica(doc, nsResolver, div, type)
|
||||
function scrapeGallica(doc, nsResolver, div, type, direct_url)
|
||||
{
|
||||
var item = new Zotero.Item;
|
||||
item.itemType = type;
|
||||
|
@ -239,8 +252,15 @@ function scrapeGallica(doc, nsResolver, div, type)
|
|||
} while (elmt = elmts.iterateNext());
|
||||
|
||||
if ( (item.url == "") || (item.url == undefined) )
|
||||
{
|
||||
if (direct_url != "")
|
||||
{
|
||||
item.url = "http://gallica.bnf.fr" + direct_url;
|
||||
}
|
||||
else
|
||||
{
|
||||
item.url = doc.location.href;
|
||||
}
|
||||
}
|
||||
item.complete();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue