首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Webscraping Roblox

Webscraping Roblox
EN

Stack Overflow用户
提问于 2021-06-23 21:27:22
回答 1查看 98关注 0票数 0

我的问题是,我正在使用selenium在roblox上抓取我的销售额,因为请求每次都会返回假的值,所以我让selenium将我的json响应写到一个文本文件中。

现在我只想从中获得销售价值,我该怎么做呢?

下面是我的python函数和response.txt

代码语言:javascript
运行
复制
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)
代码语言:javascript
运行
复制
{"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}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-23 22:19:23

如果您使用import json,则Sales将显示为:

代码语言:javascript
运行
复制
json.loads(apiResponseText)["Sales"]

下面是一个小示例:

代码语言:javascript
运行
复制
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)

输出结果为:

代码语言:javascript
运行
复制
20624
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68100746

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档