Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit. #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions scidownl/scihub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
STD_INPUT = colored('[INPUT] ', 'blue')

class SciHub(object):
def __init__(self, doi, out='.'):
def __init__(self, doi, out='.', title=None):
self.doi = doi
self.out = out
self.title = title
self.sess = requests.Session()
self.check_out_path()
self.read_available_links()
Expand Down Expand Up @@ -107,16 +108,15 @@ def find_pdf_in_html(self, html):
'pdf_url': (str) real url of the pdf.
'title': (str) title of the article.
}
"""
"""
pdf = {}
soup = BeautifulSoup(html, 'html.parser')

pdf_url = soup.find('iframe', {'id': 'pdf'}).attrs['src'].split('#')[0]
soup = BeautifulSoup(html, 'html.parser')
pdf_url = soup.find('embed', {'id': 'pdf'}).attrs['src'].split('#')[0]
pdf['pdf_url'] = pdf_url.replace('https', 'http') if 'http' in pdf_url else 'http:' + pdf_url

title = ' '.join(self._trim(soup.title.text.split('|')[1]).split('/')).split('.')[0]
title = title if title else pdf['pdf_url'].split('/')[-1].split('.pdf')[0]
pdf['title'] = self.check_title(title)
#title = ' '.join(self._trim(soup.title.text.split('|')[1]).split('/')).split('.')[0]
#title = title if title else pdf['pdf_url'].split('/')[-1].split('.pdf')[0]
self.title = self.title if self.title else pdf['pdf_url'].split('/')[-1].split('.pdf')[0]
pdf['title'] = self.check_title(self.title)
print(STD_INFO + colored('PDF url', attrs=['bold']) + " -> \n\t%s" %(pdf['pdf_url']))
print(STD_INFO + colored('Article title', attrs=['bold']) + " -> \n\t%s" %(pdf['title']))
return pdf
Expand Down