Skip to content

Commit 047f4a1

Browse files
committed
Merge branch 'master' into pr/9
2 parents 22c213b + b1987a0 commit 047f4a1

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

itunes_app_scraper/scraper.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class AppStoreScraper:
2525
can be found at https://github.com/facundoolano/app-store-scraper.
2626
"""
2727

28-
def get_app_ids_for_query(self, term, num=50, page=1, country="nl", lang="nl", timeout=None):
28+
def get_app_ids_for_query(self, term, num=50, page=1, country="nl", lang="nl", timeout=None, timeout=None):
2929
"""
3030
Retrieve suggested app IDs for search query
3131
3232
:param str term: Search query
33-
:param int num: Amount of items to return per page, default 50
34-
:param int page: Amount of pages to return
33+
:param int|None num: Amount of items to return per page, default 50
34+
:param int|None page: Amount of pages to return
3535
:param str country: Two-letter country code of store to search in,
3636
default 'nl'
3737
:param str lang: Language code to search with, default 'nl'
@@ -45,7 +45,10 @@ def get_app_ids_for_query(self, term, num=50, page=1, country="nl", lang="nl", t
4545
url = "https://search.itunes.apple.com/WebObjects/MZStore.woa/wa/search?clientApplication=Software&media=software&term="
4646
url += quote_plus(term)
4747

48-
amount = int(num) * int(page)
48+
if num is None or page is None:
49+
amount = None
50+
else:
51+
amount = int(num) * int(page)
4952

5053
country = self.get_store_id_for_country(country)
5154
headers = {
@@ -99,6 +102,7 @@ def get_app_ids_for_collection(self, collection="", category="", num=50, country
99102
return result["resultIds"]
100103

101104
def get_apps_for_developer(self, developer_id, country="nl", lang="", timeout=None):
105+
def get_app_ids_for_developer(self, developer_id, country="nl", lang="", timeout=None):
102106
"""
103107
Retrieve Apps linked to given developer
104108

scraper_test.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ def test_country_code_does_not_exist():
4848
scraper = AppStoreScraper()
4949
with pytest.raises(AppStoreException, match="Country code not found for XZ"):
5050
scraper.get_store_id_for_country('xz')
51+
52+
def test_query_multiple_pages():
53+
query = "game"
54+
scraper = AppStoreScraper()
55+
results = set()
56+
for page in range(1,4):
57+
page_results = scraper.get_app_ids_for_query(query, country="us", lang="en", page=page)
58+
if page_results:
59+
[results.add(x) for x in page_results]
60+
assert len(results) > (page-1)*50
61+
print(f"Total results for query {query}: {len(results)}")

0 commit comments

Comments
 (0)