Skip to content

Commit 568d4ad

Browse files
Merge pull request #542 from keko24/main
Fixed an issue where search_pubs returns an empty response when only a single publication exists for the query.
2 parents c6b579d + 2cd59b3 commit 568d4ad

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

scholarly/publication_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _load_url(self, url: str):
5858
# this is temporary until setup json file
5959
self._soup = self._nav._get_soup(url)
6060
self._pos = 0
61-
self._rows = self._soup.find_all('div', class_='gs_r gs_or gs_scl') + self._soup.find_all('div', class_='gsc_mpat_ttl')
61+
self._rows = self._soup.find_all('div', class_='gs_r gs_or gs_scl') + self._soup.find_all('div', class_='gs_r gs_or gs_scl gs_fmar') + self._soup.find_all('div', class_='gsc_mpat_ttl')
6262

6363
def _get_total_results(self):
6464
if self._soup.find("div", class_="gs_pda"):
@@ -70,7 +70,7 @@ def _get_total_results(self):
7070
match = re.match(pattern=r'(^|\s*About)\s*([0-9,\.\s’]+)', string=x.text)
7171
if match:
7272
return int(re.sub(pattern=r'[,\.\s’]',repl='', string=match.group(2)))
73-
return 0
73+
return len(self._rows)
7474

7575
# Iterator protocol
7676

test_module.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,23 @@ def test_search_pubs(self):
718718
titles = [p['bib']['title'] for p in pubs]
719719
self.assertIn('Visual perception of the physical stability of asymmetric three-dimensional objects', titles)
720720

721+
def test_search_pubs_single_pub(self):
722+
"""
723+
As of Jun 24, 2024 there are is only one pub that fits the search term:
724+
[Perception of physical stability and center of mass of 3D objects].
725+
726+
Check that it returns a proper result and the total results for that search term is equal to 1.
727+
"""
728+
pub = scholarly.search_single_pub("Perception of physical stability and center of mass of 3D objects")
729+
pubs = list(scholarly.search_pubs("Perception of physical stability and center of mass of 3D objects"))
730+
# Check that the first entry in pubs is the same as pub.
731+
# Checking for quality holds for non-dict entries only.
732+
for key in {'author_id', 'pub_url', 'num_citations'}:
733+
self.assertEqual(pub[key], pubs[0][key])
734+
for key in {'title', 'pub_year', 'venue'}:
735+
self.assertEqual(pub['bib'][key], pubs[0]['bib'][key])
736+
self.assertEqual(len(pubs), 1)
737+
721738
def test_search_pubs_total_results(self):
722739
"""
723740
As of September 16, 2021 there are 32 pubs that fit the search term:

0 commit comments

Comments
 (0)