0
我收到两个列表的数据,我想将它们都保存在一个json文件中,有人可以帮助我。 我使用硒在一个json文件中保存两个列表
def get_name(self):
name = []
name = self.find_elements_by_class_name ('item-desc')
price = []
price = self.find_elements_by_class_name ('item-goodPrice')
for names in name :
names = (names.text)
#print names
for prices in price :
prices = (prices.text)
#print price
我尝试一下,但它工作正常,但是当我尝试使用遵循脚本我有一个:类型错误:<函数转储在0x7f2671d9c500>不是JSON序列 json_data = json.dumps({ '名称':名称, '价格':价格}) \t \t张开( '的data.txt' ,'w')as outfile: \t \t \t json.dump(json.dumps,outfile) –
@MedDahas,在你的代码中有一个错误:你应该使用'json.dump(json_dumps,outfile)'而不是' json.dump(json.dumps,outfile)'..你也可能需要'outfile.write(json_dumps)'将你的'json'写入文件 – Andersson