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

Add in PDF link in publication fill #536

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions scholarly/publication_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def _scholar_pub(self, __data, publication: Publication):
if title.find('a'):
publication['pub_url'] = title.find('a')['href']

pdf_div = __data.find('div', class_='gs_ggs gs_fl')
if pdf_div and pdf_div.find('a', href=True):
publication['pdf_url'] = pdf_div.find('a')['href']

author_div_element = databox.find('div', class_='gs_a')
authorinfo = author_div_element.text
authorinfo = authorinfo.replace(u'\xa0', u' ') # NBSP
Expand Down Expand Up @@ -286,6 +290,10 @@ def fill(self, publication: Publication)->Publication:
if soup.find('a', class_='gsc_oci_title_link'):
publication['pub_url'] = soup.find(
'a', class_='gsc_oci_title_link')['href']
if soup.find('div', class_='gsc_oci_title_ggi'):
link = soup.find('a', attrs={'data-clk': True})
if link:
publication['pdf_url'] = link['href']
for item in soup.find_all('div', class_='gs_scl'):
key = item.find(class_='gsc_oci_field').text.strip().lower()
val = item.find(class_='gsc_oci_value')
Expand Down
6 changes: 4 additions & 2 deletions test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def test_search_pubs(self):
pubs = list(scholarly.search_pubs('"naive physics" stability "3d shape"'))
# Check that the first entry in pubs is the same as pub.
# Checking for quality holds for non-dict entries only.
for key in {'author_id', 'pub_url', 'num_citations'}:
for key in {'author_id', 'pub_url', 'pdf_url', 'num_citations'}:
self.assertEqual(pub[key], pubs[0][key])
for key in {'title', 'pub_year', 'venue'}:
self.assertEqual(pub['bib'][key], pubs[0]['bib'][key])
Expand Down Expand Up @@ -753,6 +753,7 @@ def test_search_pubs_filling_publication_contents(self):
self.assertTrue(f['bib']['publisher'] == u'The Association for Research in Vision and Ophthalmology')
self.assertTrue(f['bib']['title'] == u'Creating correct blur and its effect on accommodation')
self.assertTrue(f['pub_url'] == u'https://jov.arvojournals.org/article.aspx?articleid=2701817')
self.assertTrue(f['pdf_url'] == u'https://jov.arvojournals.org/arvo/content_public/journal/jov/937491/i1534-7362-18-9-1.pdf')
self.assertTrue(f['bib']['volume'] == '18')
self.assertTrue(f['bib']['pub_year'] == u'2018')

Expand All @@ -769,6 +770,7 @@ def test_related_articles_from_author(self):
# Typically, the same publication is returned as the most related article
same_article = next(related_articles)
self.assertEqual(pub["pub_url"], same_article["pub_url"])
self.assertEqual(pub["pdf_url"], same_article["pdf_url"])
for key in {'title', 'pub_year'}:
self.assertEqual(str(pub['bib'][key]), (same_article['bib'][key]))

Expand All @@ -787,7 +789,7 @@ def test_related_articles_from_publication(self):
related_articles = scholarly.get_related_articles(pub)
# Typically, the same publication is returned as the most related article
same_article = next(related_articles)
for key in {'author_id', 'pub_url', 'num_citations'}:
for key in {'author_id', 'pub_url', 'pdf_url', 'num_citations'}:
self.assertEqual(pub[key], same_article[key])
for key in {'title', 'pub_year'}:
self.assertEqual(pub['bib'][key], same_article['bib'][key])
Expand Down