#通过一个python的google搜索引擎模块实现简单关键字批量下载pdf工具
import google
import requests
def download_file(url,index):
local_filename=index+"-"+url.split("/")[-1]
r=requests.get(url,stream=True)
with open(local_filename,"wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
f.flush
return local_filename
g=google.search('site:*.gov.ph filetype:pdf',tld='com.hk')
index=1
for url in g:
if url.endswith(".pdf"):
file_path=download_file(url,str(index))
print "downloading:"+url+"->"+file_path
index+=1
print "all download finished"