当我想要的属性在子数据中,如何在网站上刮擦网站上的数据?
我正在网站上进行取消,并想检索有关“统计”属性的数据,然后是“ 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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须一次访问一个属性。
尝试这个
导入的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']