Upload google_play_scraper/features/search.py
Browse files
google_play_scraper/features/search.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Search for applications."""
|
| 2 |
+
from typing import List, Dict
|
| 3 |
+
from google_play_scraper.utils.http_utils import get
|
| 4 |
+
from google_play_scraper.constants.google_play import SEARCH_URL_FORMAT
|
| 5 |
+
from google_play_scraper.constants.element import SEARCH_SELECTORS
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def search(query: str, lang: str = "en", country: str = "us", n_hits: int = 20) -> List[Dict]:
|
| 9 |
+
"""Search apps by query."""
|
| 10 |
+
url = SEARCH_URL_FORMAT.format(query=query, lang=lang, country=country, n_hits=n_hits)
|
| 11 |
+
response = get(url)
|
| 12 |
+
|
| 13 |
+
results = []
|
| 14 |
+
for item in response.get("results", []):
|
| 15 |
+
app_data = {}
|
| 16 |
+
for key, selector in SEARCH_SELECTORS.items():
|
| 17 |
+
app_data[key] = item.get(selector)
|
| 18 |
+
results.append(app_data)
|
| 19 |
+
|
| 20 |
+
return results
|