python - 用python和json编码
问题描述
我不明白如何使用 python 进行编码。
import json
from bs4 import BeautifulSoup
soup = BeautifulSoup('A lot of HTML here', 'html.parser')
rec_titre = soup.find_all("div", {"class": "c-toparticle__title"})
trait_titre = rec_titre[0].text.replace("\n", '').strip()
dataEcho.append({'Titre': trait_titre, 'content': trait_content, 'uri': "https://www.lecho.be" + rec_uri})
with open('data.json', 'w') as outfile:
json.dump(dataEcho, outfile, sort_keys=True, indent=4, separators=(',', ': '))
结果是我的 Json 文件:
[
{
"Titre": "Amay | Vers un troisi\u00c3\u00a8me mandat pour Jean-Michel Javaux",
"content": "L\u00e2\u0080\u0099ex copr\u00c3\u00a9sident d\u00e2\u0080\u0099Ecolo a demand\u00c3\u00a9 (et obtenu) une d\u00c3\u00a9rogation de son parti Ecolo pour pouvoir briguer un nouveau mandat ma\u00c3\u00aforal.",
"uri": "https://www.lecho.be/dossier/zoom-communal/amay-vers-un-troisieme-mandat-pour-jean-michel-javaux/10032845.html"
}
]
编辑 :
我一直在寻找今天早上不可能找到。我在python3
代码在这里|| 只是想在我的 json 中有 utf-8 ......
杰森:
[
{
"Titre": "Amay | Vers un troisième mandat pour Jean-Michel Javaux",
"content": "Lâex coprésident dâEcolo a demandé (et obtenu) une dérogation de son parti pour pouvoir briguer un nouveau mandat maïoral.",
"uri": "https://www.lecho.be/dossier/zoom-communal/amay-vers-un-troisieme-mandat-pour-jean-michel-javaux/10032845.html"
}
]
解决方案
推荐阅读
- parquet - 是否可以用 pyarrow 编写镶木地板统计信息?
- android - 如何从 string.xml 文件中获取这种类型的数组到 android 活动
- botframework - 无法构建和部署默认 Azure Web Bot
- c++ - C++ 删除 [] 崩溃
- java - 如何从用户ID子Firebase(Android)中的子项中获取推送数据?
- c++ - 对象内部的对象和维护对象的一个实例的问题
- c# - 可交互对象 Unity
- python - tensorflow:如何交错两个张量的列(例如使用 tf.scatter_nd)?
- c# - 使用表中的多行作为属性
- ag-grid - 按下“应用”按钮后,Ag-Grid 隐藏迷你过滤器