Spaces:
Sleeping
Sleeping
File size: 1,617 Bytes
75788a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | """Test script to check what Google Shopping Light API returns."""
from serpapi import GoogleSearch
from config import settings
import json
def test_api_response():
"""Check what fields the API returns."""
print("=" * 70)
print("Testing Google Shopping Light API Response")
print("=" * 70)
params = {
"engine": "google_shopping_light",
"q": "mobile under 2000 INR",
"gl": "in",
"hl": "en",
"api_key": settings.serpapi_api_key,
"max_price": 2000
}
print("\n[Params]")
print(json.dumps({k: v for k, v in params.items() if k != "api_key"}, indent=2))
print("\n[Calling API...]")
search = GoogleSearch(params)
results = search.get_dict()
shopping_results = results.get("shopping_results", [])
print(f"\n[Found {len(shopping_results)} products]")
if shopping_results:
print("\n[First Product Fields]:")
first = shopping_results[0]
for key, value in first.items():
# Truncate long values
value_str = str(value)[:100] if len(str(value)) > 100 else str(value)
print(f" {key}: {value_str}")
print("\n[Link Field Check]:")
print(f" 'link' exists: {'link' in first}")
print(f" 'product_link' exists: {'product_link' in first}")
if 'product_link' in first:
print(f" product_link value: {first['product_link']}")
if 'link' in first:
print(f" link value: {first['link']}")
print("\n" + "=" * 70)
if __name__ == "__main__":
test_api_response()
|