【问题标题】:Python : Remove tag and replace \u00a0 in json filePython:删除标签并替换 json 文件中的 \u00a0
【发布时间】:2016-05-09 16:55:29
【问题描述】:

我有这样的 json 文件:

[
    {
       "content": ["<p style=\"text-align:justify;\"> This is content1</p>"],
       "title" : ["This is\u00a0title 1"]
    },
    {
       "content": ["<p style=\"text-align:justify;\"> This is content2</p>"],
       "title" : ["This is\u00a0title 2"]
    }
]

我想要这样的 json:

[
        {
           "content": ["This is content1"],
           "title" : ["This is title 1"]
        },
        {
           "content": ["This is content2"],
           "title" : ["This is title 2"]
        }
    ]

我想删除 HTML 标签并将 \u00a0 替换为 " "。 怎么做?

【问题讨论】:

  • 那么预期的输出是什么?到目前为止,你自己尝试过什么,你在哪里卡住了?
  • @MartijnPieters 我已经编辑过了
  • 这里有很多答案展示了如何从字符串中剥离 HTML,或者如何用另一个字符替换某个字符(这里是带空格的换行符)。 这些问题已经解决了。你查过这些答案吗?您在尝试应用时遇到了哪些问题?

标签: python html json unicode


【解决方案1】:

从 Python json module 开始。这将允许您读取 JSON 字符串并将其写入 Python 数据结构。然后使用普通的 Python 工具来处理数据。

要处理 HTML,请查看 Beautiful Soup

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2019-06-13
    相关资源
    最近更新 更多