当我想要的属性在子数据中,如何在网站上刮擦网站上的数据?

发布于 2025-01-28 22:33:08 字数 698 浏览 1 评论 0原文

我正在网站上进行取消,并想检索有关“统计”属性的数据,然后是“ ivey_count”数据。但是我不知道如何在其他数据中检索这些属性。我尝试使用此代码

stats = p ['Stats.interest_count']

但失败。

我要报废的数据。

源代码

products = r['data']
for p in products:
name = p['name']
price = p['price']
stok = p['stock']
stats =p['stats.interest_count']
count+=1
print('No :',count, 'name :',name, 'price:',price, 'stok :', stok, 'stats :', stats)
write = csv.writer(open('{}.csv'.format(key), 'a',newline=''))
data = [nama, harga, stok]
write.writerow(data)

I'm doing scrapping on a website and want to retrieve data on the 'stats' attribute then 'interest_count' data. But I don't know how to retrieve these attributes if they are in other data. I have tried with this code

stats =p['stats.interest_count']

but failed.

the data that I'm scrapping.

enter image description here

source code

products = r['data']
for p in products:
name = p['name']
price = p['price']
stok = p['stock']
stats =p['stats.interest_count']
count+=1
print('No :',count, 'name :',name, 'price:',price, 'stok :', stok, 'stats :', stats)
write = csv.writer(open('{}.csv'.format(key), 'a',newline=''))
data = [nama, harga, stok]
write.writerow(data)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梅倚清风 2025-02-04 22:33:08

您必须一次访问一个属性。

尝试这个

导入的JSON
stats = json.loads(p ['stats])['ivelion_count']

或this

Stats = p ['stats'] ['ivey_count']

You must access the attributes one at a time.

Try this

import json
stats = json.loads(p['stats])['interest_count']

Or this

stats =p['stats']['interest_count']

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文