Python实现 下载IJCAI会议所有论文
原文链接:http://www.one2know.cn/python10/
import requests
import threading
def get_file_content(num):
savepath = '%04d.pdf' % (num)
suburl = 'https://www.ijcai.org/proceedings/2018/%04d.pdf' % (num)
r = requests.get(suburl)
f = open(savepath,'wb') # 用'wb'读取非文本文件pdf
f.write(r.content) # r.content -> requests中的二进制响应内容:以字节的方式访问请求响应体,对于非文本请求
f.close()
def get_file_content_arange(min,max):
for num in range(min,max+1):
print('doanloading %04d.pdf...' % (num))
get_file_content(num)
threads = []
t1 = threading.Thread(target=get_file_content_arange,args=(1,221))
threads.append(t1)
t2 = threading.Thread(target=get_file_content_arange, args=(221,440))
threads.append(t2)
t3 = threading.Thread(target=get_file_content_arange, args=(440,658))
threads.append(t3)
t4 = threading.Thread(target=get_file_content_arange, args=(658,870,))
threads.append(t4)
for t in threads:
t.start()