我正在尝试将URL(不是文本文件)的内容写入字典。 URL有一个字典字典,如下所示:
from A import *
我的猜测是将此URL保存为TXT文件,然后使用此方法:
Writing a dict to txt file and reading it back?
然而,我正在努力,因为一旦我把它变成了一个txt文件并尝试评估它,转义字符会引起一些问题。
同时这很好用:
{{"id":15160,"icimsId":247092,"shortDescription":"ABC Leadership Development Program - Retail & Consumer\n\n\u00a3 Competitive basic salary + sign on bonuses + benefits\nClosing date: 30th June 2014\n\nWork hard. Have fun. Make history.\n\nABC opened its","url":"\/jobs\/247092\/ABC-mba-leadership-development-program-uk","title":"ABC MBA Leadership Development Program (UK) ","jobCategory":"Buying, Planning, & Instock Management","location":"GB, Slough","teamCategory":"University Recruiting","team":null}}
答案 0 :(得分:3)
作为可能的解决方案之一,我建议使用json
模块来解析此字符串。
这样的事情:
import json
with open('file_with_dict.txt', 'r') as f:
dict_string = json.load(f)
print(dict_string['jobs'])
希望,这对你有帮助。