Skip to content

Commit

Permalink
Catch case when developer_id is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
danieliu committed Mar 2, 2019
1 parent 01e32af commit 27bca88
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
10 changes: 8 additions & 2 deletions play_scraper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ def parse_app_details(soup):

offers_iap = bool(additional_info_data.get('iap_range'))

dev_id = soup.select_one('a.hrTbp.R8zArc').attrs['href'].split('=')[1]
try:
dev_id = soup.select_one('a.hrTbp.R8zArc').attrs['href'].split('=')[1]
except IndexError:
dev_id = None
developer_id = dev_id if dev_id else None

data = {
Expand Down Expand Up @@ -357,7 +360,10 @@ def parse_card_info(soup):

dev_soup = soup.select_one('a.subtitle')
developer = dev_soup.attrs['title']
developer_id = dev_soup.attrs['href'].split('=')[1]
try:
developer_id = dev_soup.attrs['href'].split('=')[1]
except IndexError:
developer_id = None

description = soup.select_one('div.description').text.strip()
score = soup.select_one('div.tiny-star')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,22 @@ def test_fetching_app_in_spanish(self):
self.assertTrue(all([app_data[x] is None
for x in ADDITIONAL_INFO_KEYS]))

def test_app_with_no_developer(self):
app_data = self.s.details('org.selfie.beauty.camera.pro')

self.assertTrue(all(key in app_data for key in DETAIL_KEYS))
self.assertEqual(len(DETAIL_KEYS), len(app_data.keys()))
self.assertEqual('org.selfie.beauty.camera.pro', app_data['app_id'])
self.assertIsNone(app_data['developer_id'])
self.assertTrue(all(x is not None and x.startswith('https://')
for x in app_data['screenshots']))

# Ensure primitive types, not bs4 NavigableString
for k, v in app_data.items():
self.assertTrue(isinstance(
v,
(basestring, bool, dict, int, list, type(None))))


class CollectionTest(ScraperTestBase):
def test_non_detailed_collection(self):
Expand Down

0 comments on commit 27bca88

Please sign in to comment.