Good afternoon,
I try to scrape nvidia's api link to get stock status (for testing) but it doesn't print the last data (productPrice
).
Here is my code :
import json
import requests
url = 'https://api.nvidia.partners/edge/product/search?page=1&limit=9&locale=fr-fr&category=GPU&gpu=RTX 3090,RTX 3080 Ti,RTX 3080,RTX 3070 Ti,RTX 3070,RTX 3060 Ti,RTX 3060&gpu_filter=RTX 3090~12,RTX 3080 Ti~7,RTX 3080~16,RTX 3070 Ti~3,RTX 3070~18,RTX 3060 Ti~8,RTX 3060~2'
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0"
}
data = requests.get(url, headers=headers).json()
for p in data["searchedProducts"]["productDetails"]:
print("{:<50} {}".format(p["productTitle"],p["productAvailable"], p["productPrice"]))
I have this (so i haven't the price):
NVIDIA GEFORCE RTX 3080 False
NVIDIA GEFORCE RTX 3070 False
NVIDIA GEFORCE RTX 3060 Ti False
NVIDIA GEFORCE RTX 3070 Ti False
NVIDIA GEFORCE RTX 3080 Ti False
Gigabyte GeForce RTX 3060 EAGLE OC 12G False
Palit NE63060019K9-190AD graphics card False
PNY VCG306012DFXPPB graphics card False
Palit NE63060T19K9-190AD graphics card False
CodePudding user response:
when you use .format
in python every {}
present a value so in order to add productPrice
you need to do this :
print("{:<50} {} {}".format(p["productTitle"],p["productAvailable"], p["productPrice"]))