{ "translatorID":"fc353b26-8911-4c34-9196-f6f567c93901", "label":"Douban", "creator":"Ace Strong", "target":"^https?://(?:www|book).douban.com/(?:subject|doulist|people/[a-zA-Z._]*/(?:do|wish|collect)|.*?status=(?:do|wish|collect)|group/[0-9]*?/collection|tag)", "minVersion":"2.0rc1", "maxVersion":"", "priority":100, "inRepository":"1", "translatorType":4, "lastUpdated":"2010-12-19 20:09:43" } /* Douban Translator Copyright (C) 2009-2010 TAO Cheng, acestrong@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ // ####################### // ##### Sample URLs ##### // ####################### /* * The starting point for an search is the URL below. * In testing, I tried the following: * * - A search listing of books * - A book page * - A doulist page * - A do page * - A wish page * - A collect page */ // http://book.douban.com/ // ################################# // #### Local utility functions #### // ################################# function trimTags(text) { return text.replace(/(<.*?>)/g, ""); } function trimMultispace(text) { return text.replace(/\n\s+/g, "\n"); } // ############################# // ##### Scraper functions ##### // ############################# function scrapeAndParse(url) { var page = Zotero.Utilities.retrieveSource(url); var pattern; // 类型 & URL var itemType = "book"; var newItem = new Zotero.Item(itemType); // Zotero.debug(itemType); newItem.url = url; // 标题 pattern = /

([\s\S]*?)<\/h1>/; if (pattern.test(page)) { var title = pattern.exec(page)[1]; newItem.title = Zotero.Utilities.trim(trimTags(title)); // Zotero.debug("title: "+title); } // 又名 pattern = /]*?>又名:(.*?)<\/span>/; if (pattern.test(page)) { var shortTitle = pattern.exec(page)[1]; newItem.shortTitle = Zotero.Utilities.trim(shortTitle); // Zotero.debug("shortTitle: "+shortTitle); } // 作者 pattern = /]*?>作者<\/span>:(.*?)<\/span>/; if (pattern.test(page)) { var authorNames = trimTags(pattern.exec(page)[1]); pattern = /(\[.*?\]|\(.*?\)|(.*?))/g; authorNames = authorNames.replace(pattern, "").split("/"); // Zotero.debug(authorNames); for (var i=0; i]*?>译者<\/span>:(.*?)<\/span>/; if (pattern.test(page)) { var translatorNames = trimTags(pattern.exec(page)[1]); pattern = /(\[.*?\])/g; translatorNames = translatorNames.replace(pattern, "").split("/"); // Zotero.debug(translatorNames); for (var i=0; i]*?>ISBN:<\/span>(.*?)/; if (pattern.test(page)) { var isbn = pattern.exec(page)[1]; newItem.ISBN = Zotero.Utilities.trim(isbn); // Zotero.debug("isbn: "+isbn); } // 页数 pattern = /]*?>页数:<\/span>(.*?)/; if (pattern.test(page)) { var numPages = pattern.exec(page)[1]; newItem.numPages = Zotero.Utilities.trim(numPages); // Zotero.debug("numPages: "+numPages); } // 出版社 pattern = /]*?>出版社:<\/span>(.*?)/; if (pattern.test(page)) { var publisher = pattern.exec(page)[1]; newItem.publisher = Zotero.Utilities.trim(publisher); // Zotero.debug("publisher: "+publisher); } // 丛书 pattern = /]*?>丛书:<\/span>(.*?)/; if (pattern.test(page)) { var series = trimTags(pattern.exec(page)[1]); newItem.series = Zotero.Utilities.trim(series); // Zotero.debug("series: "+series); } // 出版年 pattern = /]*?>出版年:<\/span>(.*?)/; if (pattern.test(page)) { var date = pattern.exec(page)[1]; newItem.date = Zotero.Utilities.trim(date); // Zotero.debug("date: "+date); } // 简介 pattern = /]*?>(?:内容)?简介[\s\S]*?<\/h2>([\s\S]*?)<\/div>/; if (pattern.test(page)) { var intro = pattern.exec(page)[1]; intro = trimTags(intro.replace(/()/g, "\n")); pattern = /\(展开全部\)([\s\S]*)/; if (pattern.test(intro)) { intro = pattern.exec(intro)[1]; } pattern = /\S/; if (pattern.test(intro)) { newItem.abstractNote = "图书简介:\n" + trimMultispace(intro); } // Zotero.debug("abstractNote: "+newItem.abstractNote); } // 作者简介 pattern = /]*?>作者简介[\s\S]*?<\/h2>([\s\S]*?)<\/div>/; if (pattern.test(page)) { var intro = pattern.exec(page)[1]; intro = trimTags(intro.replace(/()/g, "\n")); pattern = /\(展开全部\)([\s\S]*)/; if (pattern.test(intro)) { intro = pattern.exec(intro)[1]; } if (newItem.abstractNote === undefined) { newItem.abstractNote = "作者简介:\n" + trimMultispace(intro); } else { newItem.abstractNote += "\n作者简介:\n" + trimMultispace(intro); } // Zotero.debug("abstractNote: "+newItem.abstractNote); } // 丛书信息 pattern = /

丛书信息<\/h2>([\s\S]*?)<\/div>/; if (pattern.test(page)) { var intro = pattern.exec(page)[1]; intro = Zotero.Utilities.trimInternal(trimTags(intro)); if (newItem.abstractNote === undefined) { newItem.abstractNote = "丛书信息:\n" + intro; } else { newItem.abstractNote += "\n丛书信息:\n" + intro; } // Zotero.debug("abstractNote: "+newItem.abstractNote); } // 标签 pattern = /豆瓣成员常用的标签([\s\S]*?)<\/div>/; if (pattern.test(page)) { var labels = pattern.exec(page)[1]; pattern = /]*?>(.*?)<\/a>/g; var result = labels.match(pattern); for (var i=0; i/g; if (pattern.test(page)) { var result = page.match(pattern); // Zotero.debug(result.length); // Zotero.debug(result[1]); pattern = /