Skip to content

Commit 0b2106a

Browse files
committed
chore: improve examples and test search requests
1 parent e5d4d08 commit 0b2106a

5 files changed

Lines changed: 14 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ import serpapi
196196
client = serpapi.Client(api_key=os.getenv("API_KEY"))
197197
results = client.search({
198198
'engine': 'home_depot',
199-
'q': 'table',
199+
'q': 'chair',
200200
})
201201
```
202202
- API Documentation: [serpapi.com/home-depot-search-api](https://serpapi.com/home-depot-search-api)
@@ -363,7 +363,7 @@ import serpapi
363363
client = serpapi.Client(api_key=os.getenv("API_KEY"))
364364
results = client.search({
365365
'engine': 'google_jobs',
366-
'q': 'coffee',
366+
'q': 'software engineer',
367367
})
368368
```
369369
- API Documentation: [serpapi.com/google-jobs-api](https://serpapi.com/google-jobs-api)
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: "Google Shopping Price Monitoring"
3-
description: "Filter Google Shopping listings by price and read selected product fields."
3+
description: "Compare US espresso-machine listings within a budget."
44
---
55

66
# Google Shopping Price Monitoring
77

8-
Filter Google Shopping listings by price to compare offers from different merchants. The example searches for espresso machines priced between 100 and 800 in the search's currency.
8+
Search Google Shopping for a De'Longhi Stilosa espresso machine in Austin, Texas, and compare offers priced from $100 to $200. The example filters the returned prices in Python using the numeric `extracted_price` field.
99

1010
## Search Filtered Products
1111

@@ -20,17 +20,17 @@ client = serpapi.Client(api_key=os.environ["SERPAPI_KEY"], timeout=20)
2020

2121
results = client.search(
2222
engine="google_shopping",
23-
q="espresso machine",
23+
q="DeLonghi Stilosa espresso machine",
2424
location="Austin, Texas",
2525
gl="us",
2626
hl="en",
27-
min_price=100,
28-
max_price=800,
29-
sort_by=1,
30-
json_restrictor="shopping_results[].{title, price, source, rating, reviews, link}",
27+
json_restrictor="error, shopping_results[].{title, price, extracted_price, source, rating, reviews, product_link}",
3128
)
3229

33-
for product in results.get("shopping_results", [])[:5]:
30+
for product in results.get("shopping_results", []):
31+
price = product.get("extracted_price")
32+
if price is None or not 100 <= price <= 200:
33+
continue
3434
print(product.get("title"))
3535
print(product.get("price"), product.get("source"))
3636
print(product.get("rating"), product.get("reviews"))
@@ -40,4 +40,4 @@ for product in results.get("shopping_results", [])[:5]:
4040

4141
Read product listings from `shopping_results`. Useful fields include `title`, `product_id`, `price`, `extracted_price`, `source`, `rating`, `reviews`, `thumbnail`, `delivery`, `product_link`, and `serpapi_immersive_product_api`.
4242

43-
Use `min_price`, `max_price`, `sort_by`, `free_shipping`, and `on_sale` to filter and order offers. To fetch more pages, use `serpapi_pagination.next` when it is present. The example limits response fields with `json_restrictor`. Include `serpapi_pagination` in that selector if you need pagination. See the [Google Shopping API documentation](https://serpapi.com/google-shopping-api) for the full parameter set.
43+
The example limits response fields with `json_restrictor` and keeps `error` so API errors remain visible. Use `extracted_price` for numeric comparisons and `price` for display. See the [Google Shopping API documentation](https://serpapi.com/google-shopping-api) for the full parameter set.

docs/examples/home-depot-product-search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ client = serpapi.Client(api_key=os.environ["SERPAPI_KEY"], timeout=20)
2020

2121
results = client.search(
2222
engine="home_depot",
23-
q="table",
23+
q="chair",
2424
)
2525

2626
for product in results.get("products", [])[:5]:

tests/example_search_google_jobs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
def test_search_google_jobs(client):
77
data = client.search({
88
'engine': 'google_jobs',
9-
'q': 'coffee',
9+
'q': 'software engineer',
1010
})
1111
assert data.get('error') is None
1212
assert data['jobs_results']

tests/example_search_home_depot_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_search_home_depot(client):
77

88
data = client.search({
99
'engine': 'home_depot',
10-
'q': 'table',
10+
'q': 'chair',
1111
})
1212
assert data.get('error') is None
1313
assert data['products']

0 commit comments

Comments
 (0)