version 0.0.12

This commit is contained in:
guanjihuan 2021-06-05 14:58:58 +08:00
parent e87d3e1103
commit 09ca7997f5
3 changed files with 83 additions and 3 deletions

View File

@ -942,4 +942,44 @@ def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', s
plt.savefig(filename+'.jpg', dpi=300)
if show == 1:
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')

View File

@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = gjh
version = 0.0.10
version = 0.0.12
author = guanjihuan
author_email = guanjihuan@163.com
description = An open source python package

View File

@ -942,4 +942,44 @@ def plot_contour(x, y, matrix, xlabel='x', ylabel='y', title='', filename='a', s
plt.savefig(filename+'.jpg', dpi=300)
if show == 1:
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')