比这篇新的文章:
windows/XP sp2 (FR) Sellcode cmd.exe 32 bytes
比这篇旧的文章: 支持豆瓣的zotero的translator
作者: Ace Strong, 点击2498次, 评论(17), 收藏者(0), , 打分:
所有评论,共17条:( 我也来说两句)
比这篇旧的文章: 支持豆瓣的zotero的translator
支持CNKI的Zotero的translator
语言: JavaScript, 标签: translator CNKI zotero 2009/02/19发布 6个月前更新 更新记录作者: Ace Strong, 点击2498次, 评论(17), 收藏者(0), , 打分:
JavaScript语言: 支持CNKI的Zotero的translator
001 {
002 "translatorID":"5c95b67b-41c5-4f55-b71a-48d5d7183063",
003 "translatorType":4,
004 "label":"CNKI",
005 "creator":"Ace Strong<acestrong@gmail.com> and Heromyth<zxpmyth@yahoo.com.cn>",
006 "target":"^https?://(?:(?:(dlib|epub|ckrd)(?:\.edu)?\.cnki\.net)|(?:[0-9\.]+))/(?:kns50|grid2008|grid20)",
007 "minVersion":"2.0.b4",
008 "maxVersion":"",
009 "priority":100,
010 "inRepository":true,
011 "lastUpdated":"2009-6-2 10:30:00"
012 }
013
014 function detectWeb(doc, url) {
015 var articleRe = /detail.aspx/;
016 var s = articleRe.exec(url);
017
018 if(s) {
019 return "journalArticle";
020 } else {
021 articleRe = /Brief.aspx/;
022 s = articleRe.exec(url);
023 if(s)
024 return "multiple";
025
026 }
027
028 return false;
029 }
030
031 function scrape(doc, url) {
032 //var namespace = doc.documentElement.namespaceURI;
033 //var nsResolver = namespace ? function(prefix) {
034 // if (prefix == "x") return namespace; else return null;
035 //} : null;
036 var nsResolver = null;
037
038 var itemType = "journalArticle";
039 // TODO: 因为中英文信息都不想丢失,所以存为两个Item,也算是中国特色吧~
040 // 但是目前只解析出中文的信息,下个版本中添加英文信息。
041 var newItem = new Zotero.Item(itemType);
042 //Zotero.debug(itemType);
043 newItem.url = url;
044
045 // 标题
046 var title = doc.title.split('-')[0];
047 //Zotero.debug("Title:"+title);
048 newItem.title = title;
049
050 // 附件,网页快照
051 var snapName = title + " (CNKI)";
052 //Zotero.debug(snapName);
053 newItem.attachments.push({document:doc, title:snapName});
054 //Zotero.debug(doc);
055
056 // 其他信息,/html/body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody
057 var dataRows = doc.evaluate('//body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody/tr', doc, nsResolver,
058 XPathResult.ANY_TYPE, null);
059 var dataRow;
060 while(dataRow = dataRows.iterateNext()) {
061 var tds = dataRow.getElementsByTagName("td");
062 var heading = Zotero.Utilities.trimInternal(tds[0].textContent);
063 var content = tds[1];
064 if(heading == "【作者中文名】" || heading == "【作者】") {
065 //Zotero.debug("Authors:");
066 var as = content.getElementsByTagName("a");
067 //Zotero.debug(as.length);
068 var i=0;
069 for(i=0;i<as.length;i++) {
070 var a = as[i];
071 newItem.creators.push(Zotero.Utilities.cleanAuthor(a.textContent, "author", true));
072 //Zotero.debug(a.textContent);
073 }
074 } else if(heading == "【文献出处】" || heading == "【刊名】") {
075 //Zotero.debug("Publication:");
076 var as = content.getElementsByTagName("a");
077 //Zotero.debug(as[0].textContent);
078 //Zotero.debug(as[3].textContent);
079 // 出版社
080 newItem.publicationTitle = as[0].textContent;
081 var parts = Zotero.Utilities.trimInternal(as[3].textContent);
082 // 出版时间
083 var year = parts.substr(0,4);
084 //Zotero.debug(year);
085 newItem.date = year;
086 // 卷号或期号
087 var pattern = /(.*)(期|卷)/
088 var testStr = parts.split(" ")[1];
089 //Zotero.debug(testStr);
090 if (pattern.test(testStr)){
091 var attr = pattern.exec(testStr);
092 //Zotero.debug(attr[1]+":"+attr[2]);
093 if(attr[2]=="期"){
094 newItem.issue = attr[1];
095 }else{
096 newItem.volume = attr[1];
097 }
098 }
099 } else if(heading == "【摘要】" || heading == "【英文摘要】") {
100 //Zotero.debug("Abstract:");
101 var abstract = null;
102 if (content.getElementsByTagName("font")[0] != null){
103 abstract = content.getElementsByTagName("font")[0].textContent;
104 }
105 else{
106 // 有些地方没有字体,直接在td标签下就是摘要。
107 abstract = content.textContent;
108 }
109 //Zotero.debug(abstract);
110 //Zotero.debug(newItem.abstractNote);
111 if(newItem.abstractNote===undefined){
112 newItem.abstractNote = Zotero.Utilities.trim(abstract);
113 }else{
114 newItem.abstractNote = newItem.abstractNote + "\n" + Zotero.Utilities.trim(abstract);
115 }
116 } else if(heading == "【DOI】") {
117 //Zotero.debug("DOI:");
118 var doi = Zotero.Utilities.trimInternal(content.textContent);
119 //Zotero.debug(doi);
120 newItem.DOI = doi;
121 } else if(heading == "【关键词】"||heading == "【英文关键词】"||heading == "【中文关键词】") {
122 //Zotero.debug("tags:");
123 var as = content.getElementsByTagName("a");
124 var i=0;
125 for(i=0;i<as.length;i++) {
126 var a = as[i];
127 //Zotero.debug(a.textContent);
128 newItem.tags.push(a.textContent);
129 }
130 }
131 }
132 // download pdf file
133 // /html/body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td[2]/a[2]
134 //var as = table3.getElementsByTagName("a");
135 //Zotero.debug(as[0].textContent);
136 //Zotero.debug(as[1].textContent);
137 //var pdfurlElmt = as[1];
138 //if (pdfurlElmt) {
139 // newItem.attachments.push({url:pdfurlElmt.href, title:"CNKI Full Text PDF", mimeType:"application/pdf", downloadable:true});
140 //}
141 //Zotero.debug(pdfurlElmt.href);
142 //Zotero.debug("finished.");
143 newItem.complete();
144 }
145
146 function doWeb(doc, url) {
147 var namespace = doc.documentElement.namespaceURI;
148 var nsResolver = null;
149
150 Zotero.debug(url);
151
152 if(detectWeb(doc, url) == "multiple") {
153 //Zotero.debug("Enter multiple~");
154 // search page
155 var items = new Array();
156
157 var tableRows = doc.evaluate('//table[4]/tbody/tr/td[4]/table[3]/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr', doc, nsResolver, XPathResult.ANY_TYPE, null);
158 //Zotero.debug("get table rows");
159 var tableRow;
160 //Zotero.debug("begin to fetch multiple title and link");
161 while(tableRow = tableRows.iterateNext()) {
162 //Zotero.debug(tableRow!=null);
163 var title = "";
164 var link = "";
165 var as = tableRow.getElementsByTagName("a");
166 for each(var a in as) {
167 if(a.textContent) {
168 // shoulde only one 'a' here.
169 link = a.href;
170 title = a.textContent;
171 }
172 }
173 //Zotero.debug(title);
174 //Zotero.debug(link);
175 if(link) {
176 items[link] = Zotero.Utilities.trimInternal(title);
177 }
178 }
179 // 让用户选择要保存哪些文献
180 items = Zotero.selectItems(items);
181 if(!items) return true;
182 //Zotero.debug("go on processing.");
183
184 var urls = new Array();
185 for(var url in items) {
186 urls.push(url);
187 }
188 } else {
189 var urls = [url];
190 }
191 //Zotero.debug(urls);
192 // 下面对每条url进行解析
193 Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); },null);
194 Zotero.wait();
195 }
002 "translatorID":"5c95b67b-41c5-4f55-b71a-48d5d7183063",
003 "translatorType":4,
004 "label":"CNKI",
005 "creator":"Ace Strong<acestrong@gmail.com> and Heromyth<zxpmyth@yahoo.com.cn>",
006 "target":"^https?://(?:(?:(dlib|epub|ckrd)(?:\.edu)?\.cnki\.net)|(?:[0-9\.]+))/(?:kns50|grid2008|grid20)",
007 "minVersion":"2.0.b4",
008 "maxVersion":"",
009 "priority":100,
010 "inRepository":true,
011 "lastUpdated":"2009-6-2 10:30:00"
012 }
013
014 function detectWeb(doc, url) {
015 var articleRe = /detail.aspx/;
016 var s = articleRe.exec(url);
017
018 if(s) {
019 return "journalArticle";
020 } else {
021 articleRe = /Brief.aspx/;
022 s = articleRe.exec(url);
023 if(s)
024 return "multiple";
025
026 }
027
028 return false;
029 }
030
031 function scrape(doc, url) {
032 //var namespace = doc.documentElement.namespaceURI;
033 //var nsResolver = namespace ? function(prefix) {
034 // if (prefix == "x") return namespace; else return null;
035 //} : null;
036 var nsResolver = null;
037
038 var itemType = "journalArticle";
039 // TODO: 因为中英文信息都不想丢失,所以存为两个Item,也算是中国特色吧~
040 // 但是目前只解析出中文的信息,下个版本中添加英文信息。
041 var newItem = new Zotero.Item(itemType);
042 //Zotero.debug(itemType);
043 newItem.url = url;
044
045 // 标题
046 var title = doc.title.split('-')[0];
047 //Zotero.debug("Title:"+title);
048 newItem.title = title;
049
050 // 附件,网页快照
051 var snapName = title + " (CNKI)";
052 //Zotero.debug(snapName);
053 newItem.attachments.push({document:doc, title:snapName});
054 //Zotero.debug(doc);
055
056 // 其他信息,/html/body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody
057 var dataRows = doc.evaluate('//body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table[2]/tbody/tr', doc, nsResolver,
058 XPathResult.ANY_TYPE, null);
059 var dataRow;
060 while(dataRow = dataRows.iterateNext()) {
061 var tds = dataRow.getElementsByTagName("td");
062 var heading = Zotero.Utilities.trimInternal(tds[0].textContent);
063 var content = tds[1];
064 if(heading == "【作者中文名】" || heading == "【作者】") {
065 //Zotero.debug("Authors:");
066 var as = content.getElementsByTagName("a");
067 //Zotero.debug(as.length);
068 var i=0;
069 for(i=0;i<as.length;i++) {
070 var a = as[i];
071 newItem.creators.push(Zotero.Utilities.cleanAuthor(a.textContent, "author", true));
072 //Zotero.debug(a.textContent);
073 }
074 } else if(heading == "【文献出处】" || heading == "【刊名】") {
075 //Zotero.debug("Publication:");
076 var as = content.getElementsByTagName("a");
077 //Zotero.debug(as[0].textContent);
078 //Zotero.debug(as[3].textContent);
079 // 出版社
080 newItem.publicationTitle = as[0].textContent;
081 var parts = Zotero.Utilities.trimInternal(as[3].textContent);
082 // 出版时间
083 var year = parts.substr(0,4);
084 //Zotero.debug(year);
085 newItem.date = year;
086 // 卷号或期号
087 var pattern = /(.*)(期|卷)/
088 var testStr = parts.split(" ")[1];
089 //Zotero.debug(testStr);
090 if (pattern.test(testStr)){
091 var attr = pattern.exec(testStr);
092 //Zotero.debug(attr[1]+":"+attr[2]);
093 if(attr[2]=="期"){
094 newItem.issue = attr[1];
095 }else{
096 newItem.volume = attr[1];
097 }
098 }
099 } else if(heading == "【摘要】" || heading == "【英文摘要】") {
100 //Zotero.debug("Abstract:");
101 var abstract = null;
102 if (content.getElementsByTagName("font")[0] != null){
103 abstract = content.getElementsByTagName("font")[0].textContent;
104 }
105 else{
106 // 有些地方没有字体,直接在td标签下就是摘要。
107 abstract = content.textContent;
108 }
109 //Zotero.debug(abstract);
110 //Zotero.debug(newItem.abstractNote);
111 if(newItem.abstractNote===undefined){
112 newItem.abstractNote = Zotero.Utilities.trim(abstract);
113 }else{
114 newItem.abstractNote = newItem.abstractNote + "\n" + Zotero.Utilities.trim(abstract);
115 }
116 } else if(heading == "【DOI】") {
117 //Zotero.debug("DOI:");
118 var doi = Zotero.Utilities.trimInternal(content.textContent);
119 //Zotero.debug(doi);
120 newItem.DOI = doi;
121 } else if(heading == "【关键词】"||heading == "【英文关键词】"||heading == "【中文关键词】") {
122 //Zotero.debug("tags:");
123 var as = content.getElementsByTagName("a");
124 var i=0;
125 for(i=0;i<as.length;i++) {
126 var a = as[i];
127 //Zotero.debug(a.textContent);
128 newItem.tags.push(a.textContent);
129 }
130 }
131 }
132 // download pdf file
133 // /html/body/table[4]/tbody/tr/td[2]/table/tbody/tr/td[2]/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td[2]/a[2]
134 //var as = table3.getElementsByTagName("a");
135 //Zotero.debug(as[0].textContent);
136 //Zotero.debug(as[1].textContent);
137 //var pdfurlElmt = as[1];
138 //if (pdfurlElmt) {
139 // newItem.attachments.push({url:pdfurlElmt.href, title:"CNKI Full Text PDF", mimeType:"application/pdf", downloadable:true});
140 //}
141 //Zotero.debug(pdfurlElmt.href);
142 //Zotero.debug("finished.");
143 newItem.complete();
144 }
145
146 function doWeb(doc, url) {
147 var namespace = doc.documentElement.namespaceURI;
148 var nsResolver = null;
149
150 Zotero.debug(url);
151
152 if(detectWeb(doc, url) == "multiple") {
153 //Zotero.debug("Enter multiple~");
154 // search page
155 var items = new Array();
156
157 var tableRows = doc.evaluate('//table[4]/tbody/tr/td[4]/table[3]/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr', doc, nsResolver, XPathResult.ANY_TYPE, null);
158 //Zotero.debug("get table rows");
159 var tableRow;
160 //Zotero.debug("begin to fetch multiple title and link");
161 while(tableRow = tableRows.iterateNext()) {
162 //Zotero.debug(tableRow!=null);
163 var title = "";
164 var link = "";
165 var as = tableRow.getElementsByTagName("a");
166 for each(var a in as) {
167 if(a.textContent) {
168 // shoulde only one 'a' here.
169 link = a.href;
170 title = a.textContent;
171 }
172 }
173 //Zotero.debug(title);
174 //Zotero.debug(link);
175 if(link) {
176 items[link] = Zotero.Utilities.trimInternal(title);
177 }
178 }
179 // 让用户选择要保存哪些文献
180 items = Zotero.selectItems(items);
181 if(!items) return true;
182 //Zotero.debug("go on processing.");
183
184 var urls = new Array();
185 for(var url in items) {
186 urls.push(url);
187 }
188 } else {
189 var urls = [url];
190 }
191 //Zotero.debug(urls);
192 // 下面对每条url进行解析
193 Zotero.Utilities.processDocuments(urls, scrape, function() { Zotero.done(); },null);
194 Zotero.wait();
195 }
所有评论,共17条:( 我也来说两句)
| 1 |
半瓶墨水
1年前
回复
呵呵这个是做啥用的啊?
|
| 2 |
Ace Strong
1年前
回复
zotero是文献管理器,Google一下就知道了,很酷的~
|
| 3 |
呵呵,原来如此,不错
|
| 4 |
zotero1984
1年前
回复
请问怎吗添加进zotero的translator库,谢谢!
|
| 5 |
Ace Strong
1年前
回复
zotero最新的是1.5beta版,也有1.0.9版,不知道你用的是哪一个版本。
|
| 6 |
zotero1984
1年前
回复
我用的是1.5版,我按照你的做法试试,非常感谢你的脚本。
|
| 7 |
zotero1984
1年前
回复
现在可以工作了,但是抓取的信息比较少,我这边只有标题和添加时间,作者和摘要,期刊名,卷号期号,页码和日期都没有,不知道是哪里出了问题。
|
| 8 |
Ace Strong
1年前
回复
抓取的信息有可能只有几个~
|
| 9 |
zotero1984
1年前
回复
我用的是学校CNKI的数据库,http://dlib.cnki.net/kns50/detail.aspx?QueryID=15&CurRec=1
|
| 10 |
Ace Strong
1年前
回复
我用的也是学校的CNKI~
|
| 11 |
Ace Strong
11个月前
回复
找到只能抓取标题和添加时间的问题所在了:文件编码问题!
|
| 12 |
不知怎的,保存不了,用的是http://epub.cnki.net/
|
| 13 |
Ace Strong
9个月前
回复
cnki最近改版了,现在没时间跟进,找时间改改~
|
| 14 |
原来是这样的,谢谢回答,
|
| 15 |
就是加了|sql与|xmlib
|
| 16 |
|
| 17 |
Ace Strong
2个月前
回复
最近用得挺好的,pdf下载功能无限期延后(水平有限没办法)~
|
代码

?
ns50|grid2008|grid20)",