0
你能幫我怎麼從字典導入到json文件,我已經從網站獲取所有標籤,但仍然混淆保存所有標籤。這是我的代碼如何添加從美麗的詞典元素到json文件
array= []
data = {}
for divdata in soup.findAll('div', {"class": "ratio9_8 box_img fl mr10"}):
for div in divdata.findAll('div', {'class': 'img_con lqd'}):
for getatag in div.findAll('a', {'data-category': 'WP Kanal Berita'},href = True):
for getimgtag in getatag.findAll('img',title=True,src=True):
array.append(getimgtag['title'])
array.append(getimgtag['src'])
array.append(getatag['href'])
data['title'] = array[0]
data['image'] = array[1]
data['link'] = array[2]
with open('data.json', 'w') as outfile:
json.dump(data, outfile)
運行程序時
,我只是得到一個字典
{"title": "......", "image": ".....", "link": "...."}