Created
June 20, 2021 04:58
-
-
Save dimitryzub/5eadcdd8f81dbe5af86bd658b0766884 to your computer and use it in GitHub Desktop.
ebay_serpapi_get_organic_search_results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from serpapi import GoogleSearch | |
import os, json | |
def get_organic_results(): | |
params = { | |
"engine": "ebay", | |
"ebay_domain": "ebay.com", | |
"_nkw": "minecraft creeper figure", | |
"api_key": os.getenv("API_KEY"), | |
} | |
search = GoogleSearch(params) | |
results = search.get_dict() | |
data = [] | |
for result in results['organic_results']: | |
try: | |
sponsoerd = result['sponsored'] | |
except: | |
sponsoerd = None | |
title = result['title'] | |
link = result['link'] | |
try: | |
subtitle = result['subtitle'] | |
except: | |
subtitle = None | |
try: | |
condition = result['condition'] | |
except: | |
condition = None | |
try: | |
shipping = result['shipping'].split(' ')[0] | |
except: | |
shipping = None | |
try: | |
price = result['price']['raw'] | |
except: | |
price = None | |
try: | |
review = result['reviews'] | |
except: | |
review = None | |
try: | |
returns = result['returns'] | |
except: | |
returns = False | |
try: | |
top_rated = result['top_rated'] | |
except: | |
top_rated = False | |
try: | |
bid_count = result['bids']['count'] | |
except: | |
bid_count = None | |
try: | |
bid_time_left = result['bids']['time_left'] | |
except: | |
bid_time_left = None | |
try: | |
buy_now_extensions = result['extensions'] | |
except: | |
buy_now_extensions = None | |
data.append({ | |
"title": title, | |
"subtitle": subtitle, | |
'link': link, | |
"price": price, | |
"shipping_cost": shipping, | |
'returns': returns, | |
"sponsored": sponsoerd, | |
"item_condition": condition, | |
'top_rated': top_rated, | |
'reviews': review, | |
'bids': {'count': bid_count, 'time_left': bid_time_left}, | |
'buy_now': buy_now_extensions, | |
}) | |
print(json.dumps(data, indent=2, ensure_ascii=False)) | |
get_organic_results() | |
# Part of the output: | |
''' | |
[ | |
{ | |
"title": "🔥Minecraft Earth Boost Minis Repairing Villager & Mining Creeper Figure", | |
"subtitle": "4 of the Minecraft Earth boost", | |
"link": "https://www.ebay.com/itm/203469124018?epid=22043750949&_trkparms=ispr%3D1&hash=item2f5fb471b2:g:JSoAAOSwzwBgqu0Y&amdata=enc%3AAQAGAAACkPYe5NmHp%252B2JMhMi7yxGiTJkPrKr5t53CooMSQt2orsSjVt3vLKCbov98Z19qhuwY9LA8W0Em6QYY3I%252Fr7%252FM8Lv%252BRg4EVj7%252FeJulg1E4gFPZsMHjNyXn7JFogjli2WhcweKt0p9AEGk6hT6ZhQ6IBAUfg7OEgFF182lbGMPjLWAnrfGSE15Q6j32Yc6PIvt4vPItRcIazFpSR3eKOJvbVT4oEAaZAMsFUl7%252FjmMIbIdG8QhV8FMPRhHFRz7QolIZUA%252FgbSAwH5EocbMsY%252FXY%252BwESDJPZ0THibIecs4fHFQHEqvi3%252Bx5EmXTW%252Fw%252BdJAOA2LjeDASPJprhpmlhZoiXAkcgstS2xlSut1lD3ghKEvr8eIrbxTPfVMxuC9vj%252FaWJoF7TiLWXXGbUL8ogOB580H%252Fe6MhCsqT4RsMKlIHVBN9bauI0gEMEG636Soc7oHZSKoz86gl91rmUOWTV4QUuKi2AJb61ysUdJ58nLOiXFlIMsbJiRJvU8QrrYGSiZr5tts%252F%252Bw9btKcIXaHYA9RprVb2Bh70lMkI74VyGPKQRV3Vj2VF0JVKm2TjUc%252BhRPZrc%252FU9lGLoLEXOk0Rijgeq8DGiiGXdf2EeFXLO6J7WYjIwJyaYQLOi5VzNvcT0YTtJBBdX%252Bgq8yv%252BEEQi6K64Gnq0Ed8V1q%252F9YOO7WAGZIW9G%252FurMmE9Mg0WB8IBvTfjzCb2dzyfprvuZZsLBtwCNpsZtrwgGi60DfGznTaX9J%252FFVWthqBVnsad5ovxIZ48HRSp8aa5LcgdUeokf22nCOwy7DrvJzfDRnhDNYG%252BrhGINq3o78FVkFTpLv%252FfBE4ot3sgzwl1a4bZwcp1MLIecgzbNXTeJ0nyJpO4pigSvigKxP1X%7Campid%3APL_CLK%7Cclp%3A2334524", | |
"price": "$27.65", | |
"shipping_cost": "+$17.55", | |
"returns": false, | |
"sponsored": null, | |
"item_condition": "Brand New", | |
"top_rated": false, | |
"reviews": null, | |
"bids": { | |
"count": null, | |
"time_left": null | |
}, | |
"buy_now": [ | |
"or Best Offer" | |
] | |
} | |
] | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment