version 0.0.12
This commit is contained in:
		| @@ -942,4 +942,44 @@ def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', s | |||||||
|         plt.savefig(filename+'.jpg', dpi=300)  |         plt.savefig(filename+'.jpg', dpi=300)  | ||||||
|     if show == 1: |     if show == 1: | ||||||
|         plt.show() |         plt.show() | ||||||
|     plt.close('all') |     plt.close('all') | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # download | ||||||
|  |  | ||||||
|  | def download_with_scihub(address=None, num=1): | ||||||
|  |     from bs4 import BeautifulSoup | ||||||
|  |     import re | ||||||
|  |     import requests | ||||||
|  |     import os | ||||||
|  |     if num==1 and address!=None: | ||||||
|  |         address_array = [address] | ||||||
|  |     else: | ||||||
|  |         address_array = [] | ||||||
|  |         for i in range(num): | ||||||
|  |             address = input('\nInput:') | ||||||
|  |             address_array.append(address) | ||||||
|  |     for address in address_array: | ||||||
|  |         r = requests.post('https://sci-hub.st/', data={'request': address}) | ||||||
|  |         print('\nResponse:', r) | ||||||
|  |         print('Address:', r.url) | ||||||
|  |         soup = BeautifulSoup(r.text, features='lxml') | ||||||
|  |         pdf_URL = soup.iframe['src'] | ||||||
|  |         if re.search(re.compile('^https:'), pdf_URL): | ||||||
|  |             pass | ||||||
|  |         else: | ||||||
|  |             pdf_URL = 'https:'+pdf_URL | ||||||
|  |         print('PDF address:', pdf_URL) | ||||||
|  |         name = re.search(re.compile('fdp.*?/'),pdf_URL[::-1]).group()[::-1][1::] | ||||||
|  |         print('PDF name:', name) | ||||||
|  |         print('Directory:', os.getcwd()) | ||||||
|  |         print('\nDownloading...') | ||||||
|  |         r = requests.get(pdf_URL, stream=True) | ||||||
|  |         with open(name, 'wb') as f: | ||||||
|  |             for chunk in r.iter_content(chunk_size=32): | ||||||
|  |                 f.write(chunk) | ||||||
|  |         print('Completed!\n') | ||||||
|  |     if num != 1: | ||||||
|  |         print('All completed!\n') | ||||||
| @@ -1,7 +1,7 @@ | |||||||
| [metadata] | [metadata] | ||||||
| # replace with your username: | # replace with your username: | ||||||
| name = gjh | name = gjh | ||||||
| version = 0.0.10 | version = 0.0.12 | ||||||
| author = guanjihuan | author = guanjihuan | ||||||
| author_email = guanjihuan@163.com | author_email = guanjihuan@163.com | ||||||
| description = An open source python package | description = An open source python package | ||||||
|   | |||||||
| @@ -942,4 +942,44 @@ def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', s | |||||||
|         plt.savefig(filename+'.jpg', dpi=300)  |         plt.savefig(filename+'.jpg', dpi=300)  | ||||||
|     if show == 1: |     if show == 1: | ||||||
|         plt.show() |         plt.show() | ||||||
|     plt.close('all') |     plt.close('all') | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | # download | ||||||
|  |  | ||||||
|  | def download_with_scihub(address=None, num=1): | ||||||
|  |     from bs4 import BeautifulSoup | ||||||
|  |     import re | ||||||
|  |     import requests | ||||||
|  |     import os | ||||||
|  |     if num==1 and address!=None: | ||||||
|  |         address_array = [address] | ||||||
|  |     else: | ||||||
|  |         address_array = [] | ||||||
|  |         for i in range(num): | ||||||
|  |             address = input('\nInput:') | ||||||
|  |             address_array.append(address) | ||||||
|  |     for address in address_array: | ||||||
|  |         r = requests.post('https://sci-hub.st/', data={'request': address}) | ||||||
|  |         print('\nResponse:', r) | ||||||
|  |         print('Address:', r.url) | ||||||
|  |         soup = BeautifulSoup(r.text, features='lxml') | ||||||
|  |         pdf_URL = soup.iframe['src'] | ||||||
|  |         if re.search(re.compile('^https:'), pdf_URL): | ||||||
|  |             pass | ||||||
|  |         else: | ||||||
|  |             pdf_URL = 'https:'+pdf_URL | ||||||
|  |         print('PDF address:', pdf_URL) | ||||||
|  |         name = re.search(re.compile('fdp.*?/'),pdf_URL[::-1]).group()[::-1][1::] | ||||||
|  |         print('PDF name:', name) | ||||||
|  |         print('Directory:', os.getcwd()) | ||||||
|  |         print('\nDownloading...') | ||||||
|  |         r = requests.get(pdf_URL, stream=True) | ||||||
|  |         with open(name, 'wb') as f: | ||||||
|  |             for chunk in r.iter_content(chunk_size=32): | ||||||
|  |                 f.write(chunk) | ||||||
|  |         print('Completed!\n') | ||||||
|  |     if num != 1: | ||||||
|  |         print('All completed!\n') | ||||||
		Reference in New Issue
	
	Block a user
	 guanjihuan
					guanjihuan