网页抓取 Roblox
Webscraping Roblox
我的问题是我正在使用 selenium 抓取我在 roblox 上的销售情况,因为每次都请求 returns 错误值,所以我让 selenium 将我的 json 响应写入文本文件。
现在我只想从中获取销售额,我该怎么做?
这是我的 python 函数,还有我的 response.txt
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)
{"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}
如果您 import json
,销售额将给出:
json.loads(apiResponseText)["Sales"]
这是一个小例子:
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)
输出为:
20624
我的问题是我正在使用 selenium 抓取我在 roblox 上的销售情况,因为每次都请求 returns 错误值,所以我让 selenium 将我的 json 响应写入文本文件。
现在我只想从中获取销售额,我该怎么做?
这是我的 python 函数,还有我的 response.txt
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)
{"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}
如果您 import json
,销售额将给出:
json.loads(apiResponseText)["Sales"]
这是一个小例子:
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)
输出为:
20624