#Python脚本
#! encoding=utf-8
import urllib2
import re
import os
def Download(url,output):
print "downloading..."+url
response = urllib2.urlopen(url)
resourceFile = open(output,"wb")
resourceFile.write(response.read())
resourceFile.close()
print "downloaded"
def Action(url,ext = "pdf",output = "."):
#1.domain
index = url.rfind("/");
domain = url[0:index+1];
print domain
request = urllib2.Request(url)
response = urllib2.urlopen(request)
#2.content
content = response.read()
# print content
#3.resource
mode = '\"([^\"]+'+ext+')\"'
pattern = re.compile(mode)
strMatch = pattern.findall(content)
size = len(strMatch)
print "file num: "+str(size)
for i in range(0,size,1):
# print strMatch[i]
one = strMatch[i]
partIndex = one.rfind('/')
if not one.startswith('http://'):
if -1!=partIndex:
directDir = one[0:partIndex+1]
else:
directDir = ""
# print directDir
try:
os.makedirs(output+"/"+directDir)
except Exception,e:
pass
fileUrl = domain+one
fileOutput = output+"/"+one
print fileUrl
print fileOutput
Download(fileUrl,fileOutput)
else:
print one
print "........."
print one[partIndex:]
fileOutput = output+"/"+one[partIndex:]
print fileOutput
Download(one,fileOutput)
#5.download
if __name__=='__main__':
print "download"
#url = "http://compgeom.cs.uiuc.edu/~jeffe/teaching/algorithms/";
Action("http://i.cs.hku.hk/~hubert/","pdf");
update :
http://www.yangzhiping.com/tech/zotero6.html
Q1. 如何批量抓取PDF文档,快速了解研究者重点
在前面的文章中,你应该学会一个重要技巧了,就是通过【google学术】,根据作者名字或者论文名字,搜索出论文全文,然后批量保存到Zotero中。
但是,现实生活中,还常常存在另一类需求。就是作者很慷慨地提供了自己所有论文的PDF文档,列在个人网站上,以备同行引用。
因为作者自己提供的文档往往清晰度更高、比【Google学术】中根据作者名字搜出来的更齐全一些。怎么批量下载,然后导入到Zotero中?让我们来举个例子。
APA今年的奖评刚出来了。每年这些奖项里面,【早期职业生涯贡献奖】 与 【杰出贡献奖】 参考价值不错,一个代表心理学未来,获奖者:http://t.cn/8kxCp3n 一个代表心理学过去,获奖者:http://t.cn/8kxCp3E
其中,Linda B. Smith很猛,近两年双丰收。才拿2013年侧重认知科学基础卓越贡献奖的David E. Rumelhart奖(现在火爆的深度学习大牛Hinton是第一个拿这个奖的),今年又拿 【杰出贡献奖】 。她的个人主页:http://t.cn/8kxphwG
我们就以她的论文为例。
步骤如下:
1、安装一个chrome的批量下载插件:
Chrome Web Store - DownloadAll
2、访问Linda B. Smith提供出版物的网页,她恰巧在自己的个人网站上,提供了PDF全文列表,网址如下:
Cognitive Development Lab - Indiana University. Bloomington