My problem is that I am web scraping my sales on Roblox with Selenium, because requests returns the false value every time so I made selenium write my JSON response to a text file.
And now I want to only get the sales value from it, how do I do this?
Python function:
def submitData(self):
self.title.setText("Roblox Sales Checker")
try:
ID = self.ID_INPUT.text()
url = f'https://api.roblox.com/Marketplace/ProductInfo?assetId={ID}'
driver.get(url)
driver.add_cookie("My Auth Cookie,but not for you :)")
driver.refresh()
search = driver.find_element_by_css_selector("body > pre").text
f = open('apiResponse.txt', 'w')
f.write(search)
f.close()
f = open('apiResponse.txt', 'r+')
apiResponseText = f.readlines()
print(apiResponseText)
response.txt
:
{"TargetId":6970745869,"ProductType":"User Product","AssetId":6970745869,"ProductId":1183920723,"Name":"beautifulSky","Description":"","AssetTypeId":10,"Creator":{"Id":2657343484,"Name":"Bestgamedev1209","CreatorType":"User","CreatorTargetId":2657343484},"IconImageAssetId":0,"Created":"2021-06-18T15:12:36.253Z","Updated":"2021-06-18T15:12:36.297Z","PriceInRobux":null,"PriceInTickets":null,"Sales":20624,"IsNew":false,"IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"Remaining":null,"MinimumMembershipLevel":0,"ContentRatingTypeId":0}
If you import json
, Sales will be given as:
json.loads(apiResponseText)["Sales"]
Here is a small example:
import json
apiResponseText='{"TargetId":6970745869,"ProductType":"User Product","AssetId":6970745869,"ProductId":1183920723,"Name":"beautifulSky","Description":"","AssetTypeId":10,"Creator":{"Id":2657343484,"Name":"Bestgamedev1209","CreatorType":"User","CreatorTargetId":2657343484},"IconImageAssetId":0,"Created":"2021-06-18T15:12:36.253Z","Updated":"2021-06-18T15:12:36.297Z","PriceInRobux":null,"PriceInTickets":null,"Sales":20624,"IsNew":false,"IsForSale":false,"IsPublicDomain":true,"IsLimited":false,"IsLimitedUnique":false,"Remaining":null,"MinimumMembershipLevel":0,"ContentRatingTypeId":0}'
y=json.loads(apiResponseText)["Sales"]
print(y)
and the output is:
20624