Skip to content

Commit 0ff3ba6

Browse files
author
vlad-outscraper
committed
add google search + news
1 parent fa6a557 commit 0ff3ba6

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ from outscraper import ApiClient
2727
api_client = ApiClient(api_key='SECRET_API_KEY')
2828
```
2929

30+
## Scrape Google Search
31+
32+
```python
33+
# Googel Search
34+
result = api_client.google_search('bitcoin')
35+
36+
# Googel Search News
37+
result = api_client.google_search_news('election', language='en')
38+
```
39+
3040
## Scrape Google Maps (Places)
3141

3242
```python

README.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ Initialization
4343
4444
api_client = ApiClient(api_key='SECRET_API_KEY')
4545
46+
Scrape Google Search
47+
---------------------------
48+
49+
.. code:: python
50+
51+
# Search for businesses in specific locations:
52+
result = api_client.google_maps_search('restaurants brooklyn usa', limit=20, language='en')
53+
54+
# Googel Search
55+
result = api_client.google_search('bitcoin')
56+
4657
Scrape Google Maps (Places)
4758
---------------------------
4859

outscraper/api_client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,37 @@ def google_search(self, query: list, language: str = 'en', region: str = None, f
111111

112112
raise Exception(f'Response status code: {response.status_code}')
113113

114+
def google_search_news(self, query: list, pages_per_query: int = 1, uule: str = None, language: str = 'en', region: str = None, fields: list = None) -> list:
115+
'''
116+
Returns search results from Google based on a given search query (or many queries).
117+
118+
Parameters:
119+
query (list | str): parameter defines the query or queries you want to search news on Google. Using a lists allows multiple queries (up to 25) to be sent in one request and save on network latency time.
120+
pages_per_query (int): parameter specifies the limit of pages to return from one query.
121+
uule (str): Google UULE parameter is used to encode a place or an exact location (with latitude and longitude) into a code. By using it you can see a Google result page like someone located at the specified location.
122+
language (str): parameter specifies the language to use for Google. Available values: "en", "de", "es", "es-419", "fr", "hr", "it", "nl", "pl", "pt-BR", "pt-PT", "vi", "tr", "ru", "ar", "th", "ko", "zh-CN", "zh-TW", "ja", "ach", "af", "ak", "ig", "az", "ban", "ceb", "xx-bork", "bs", "br", "ca", "cs", "sn", "co", "cy", "da", "yo", "et", "xx-elmer", "eo", "eu", "ee", "tl", "fil", "fo", "fy", "gaa", "ga", "gd", "gl", "gn", "xx-hacker", "ht", "ha", "haw", "bem", "rn", "id", "ia", "xh", "zu", "is", "jw", "rw", "sw", "tlh", "kg", "mfe", "kri", "la", "lv", "to", "lt", "ln", "loz", "lua", "lg", "hu", "mg", "mt", "mi", "ms", "pcm", "no", "nso", "ny", "nn", "uz", "oc", "om", "xx-pirate", "ro", "rm", "qu", "nyn", "crs", "sq", "sk", "sl", "so", "st", "sr-ME", "sr-Latn", "su", "fi", "sv", "tn", "tum", "tk", "tw", "wo", "el", "be", "bg", "ky", "kk", "mk", "mn", "sr", "tt", "tg", "uk", "ka", "hy", "yi", "iw", "ug", "ur", "ps", "sd", "fa", "ckb", "ti", "am", "ne", "mr", "hi", "bn", "pa", "gu", "or", "ta", "te", "kn", "ml", "si", "lo", "my", "km", "chr".
123+
region (str): parameter specifies the region to use for Google. Available values: "AF", "AL", "DZ", "AS", "AD", "AO", "AI", "AG", "AR", "AM", "AU", "AT", "AZ", "BS", "BH", "BD", "BY", "BE", "BZ", "BJ", "BT", "BO", "BA", "BW", "BR", "VG", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "CF", "TD", "CL", "CN", "CO", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "EE", "ET", "FJ", "FI", "FR", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GT", "GG", "GY", "HT", "HN", "HK", "HU", "IS", "IN", "ID", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "KW", "KG", "LA", "LV", "LB", "LS", "LY", "LI", "LT", "LU", "MG", "MW", "MY", "MV", "ML", "MT", "MU", "MX", "FM", "MD", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NZ", "NI", "NE", "NG", "NU", "MK", "NO", "OM", "PK", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RO", "RU", "RW", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SK", "SI", "SB", "SO", "ZA", "KR", "ES", "LK", "SH", "VC", "SR", "SE", "CH", "TW", "TJ", "TZ", "TH", "TL", "TG", "TO", "TT", "TN", "TR", "TM", "VI", "UG", "UA", "AE", "GB", "US", "UY", "UZ", "VU", "VE", "VN", "ZM", "ZW".
124+
fields (list): parameter defines which fields you want to include with each item returned in the response. By default, it returns all fields.
125+
126+
Returns:
127+
list: json result
128+
129+
See: https://app.outscraper.com/api-docs#tag/Google-Search/paths/~1google-search-news/get
130+
'''
131+
response = requests.get(f'{self._api_url}/google-search-news', params={
132+
'query': as_list(query),
133+
'pagesPerQuery': pages_per_query,
134+
'uule': uule,
135+
'language': language,
136+
'region': region,
137+
'fields': ','.join(fields) if fields else '',
138+
}, headers=self._api_headers)
139+
140+
if 199 < response.status_code < 300:
141+
return self._wait_request_archive(response.json()['id']).get('data', [])
142+
143+
raise Exception(f'Response status code: {response.status_code}')
144+
114145
def google_maps_search(self, query: list, limit: int = 500, extract_contacts: bool = False, drop_duplicates: bool = False,
115146
coordinates: str = None, language: str = 'en', region: str = None, fields: list = None
116147
) -> list:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def readme():
88

99
setup(
1010
name='google-services-api',
11-
version='1.4.0',
11+
version='1.5.0',
1212
description='Google Maps and Google Maps reviews scraper by Outscraper API',
1313
long_description=readme(),
1414
classifiers = ['Programming Language :: Python',

0 commit comments

Comments
 (0)