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