【发布时间】:2015-12-22 20:02:06
【问题描述】:
我的脚本有编码问题。这是我的脚本:
def parse_airfields():
html = urlopen('https://www.sia.aviation-civile.gouv.fr/aip/enligne/FRANCE/AIRAC-2015-09-17/html/eAIP/FR-AD-1.3-fr-FR.html').read()
html = html.decode('utf-8')
soup = BeautifulSoup(html, 'lxml')
# A lot of work [....]
return airfields
if __name__ == '__main__':
airfields = parse_airfields()
for airfield in airfields:
for value in airfield.values():
if isinstance(value, str):
value.encode('utf-8')
with open('airfields.json', 'w') as airfields_file:
json.dump(airfields, airfields_file, indent=4, sort_keys=True)
我尝试不使用encode() 和不使用decode(),但结果相同... JSON 文件中的编码问题:
为什么?感谢您的帮助!
【问题讨论】:
-
什么问题?此外,调用
encode()方法的那一行会处理结果。
标签: python json python-3.x encoding beautifulsoup