Skip to content

Commit 70c6ed4

Browse files
author
vlad-outscraper
committed
2 parents a8bcfda + 64b173e commit 70c6ed4

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

examples/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,55 @@ for place in results:
8383
print('new reviews', len(new_reviews))
8484
```
8585

86+
## Example 5: Scrape And Save Places Into a Table
87+
88+
```python
89+
results = api_client.google_maps_search_v2(
90+
['restaurants brooklyn usa', 'bars brooklyn usa'],
91+
limit=500,
92+
language='en',
93+
region='US',
94+
)
95+
96+
# combine places from all queries into a list
97+
all_places = []
98+
for query_places in results:
99+
all_places.extend(query_places)
100+
101+
# save to file
102+
import pandas as pd
103+
df = pd.DataFrame(all_places)
104+
df.to_csv('results.csv', index=None)
105+
```
106+
107+
## Example 6: Get Places Information From a list of Place IDs (Multithreading)
108+
109+
```python
110+
from functools import partial
111+
from multiprocessing.pool import ThreadPool
112+
113+
place_ids = [
114+
'ChIJNw4_-cWXyFYRF_4GTtujVsw',
115+
'ChIJ39fGAcGXyFYRNdHIXy-W5BA',
116+
'ChIJVVVl-cWXyFYRQYBCEkX0W5Y',
117+
'ChIJScUP1R6XyFYR0sY1UwNzq-c',
118+
'ChIJmeiNBMeXyFYRzQrnMMDV8Jc',
119+
'ChIJifOTBMeXyFYRmu3EGp_QBuY',
120+
'ChIJ1fwt-cWXyFYR2cjoDAGs9UI',
121+
'ChIJ5zQrTzSXyFYRuiY31iE7M1s',
122+
'ChIJQSyf4huXyFYRpP9W4rtBelA',
123+
'ChIJRWK5W2-byFYRiaF9vVgzZA4'
124+
]
125+
126+
# fast download in 4 threads
127+
pool = ThreadPool(4)
128+
results = pool.map(partial(api_client.google_maps_search_v2, limit=500, language='en', region='US'), place_ids)
129+
130+
# combine places from all queries
131+
all_places = []
132+
for query_places in results:
133+
if query_places and query_places[0]:
134+
all_places.append(query_places[0][0])
135+
else:
136+
all_places.append({})
137+
```

0 commit comments

Comments
 (0)