1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import requests import os import re root_url=r'http://openaccess.thecvf.com/CVPR2018.py' def get_html(url): headers={'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1; m1 metal Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043409 Safari/537.36 V1ANDSQ7.2.5744YYBD QQ/7.2.5.3305 NetType/WIFI WebP/0.3.0 Pixel/1080'} html=requests.get(root_url,headers=headers) reg = r'(?:href|HREF)="?((?:http://)?.+?\.pdf)' url_lst = re.findall(reg,html.text) return(url_lst) n=0 for i in get_html(root_url): n+=1 print("打印第"+str(n)+"篇论文") headers={'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1; m1 metal Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043409 Safari/537.36 V1ANDSQ7.2.5744YYBD QQ/7.2.5.3305 NetType/WIFI WebP/0.3.0 Pixel/1080'} FILE_DIR=r"C:\Users\zjk\Desktop\大二上论文" pdf_name=i.split('/')[-1] response = requests.get('http://openaccess.thecvf.com/'+i,headers=headers,stream=True) if not os.path.exists(FILE_DIR): os.makedirs(FILE_DIR) with open(os.path.join(FILE_DIR,pdf_name),"wb") as pdf_file: for content in response.iter_content(): pdf_file.write(content)
|