Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除HTML标记并使用JSON转换为字符串?_Python_Html_Json_Unicode_Scrapy - Fatal编程技术网

Python 删除HTML标记并使用JSON转换为字符串?

Python 删除HTML标记并使用JSON转换为字符串?,python,html,json,unicode,scrapy,Python,Html,Json,Unicode,Scrapy,我在Windows Vista 64位上使用Python.org 2.7 64位版本。我有下面的代码,它从Guardian API返回数据: import requests from scrapy.utils.markup import remove_tags def get_content(): api_url = 'http://beta.content.guardianapis.com/football' payload = { 'api-key':

我在Windows Vista 64位上使用Python.org 2.7 64位版本。我有下面的代码,它从Guardian API返回数据:

import requests
from scrapy.utils.markup import remove_tags

def get_content():
    api_url = 'http://beta.content.guardianapis.com/football'
    payload = {
        'api-key':              '',
        'page-size':            10,
        'show-editors-picks':   'true',
        'show-elements':        'image',
        'show-fields':          'all'

    }
    response = requests.get(api_url, params=payload)
    data = response.json() # convert json to python-readable format
    data2 = "".join(data)
    print remove_tags(data2).encode('utf-8')
    return data
get_content()
如何删除结果中返回的所有HTML标记并转换为Unicode?在scrapy中使用XML之前,我也做过类似的工作,其中有以下几条逻辑:

print remove_tags(body2).encode('utf-8')
在本例中,m“body2”是一个字符串


谢谢

在您尝试删除标记并转换为unicode之前,您可以发布data2的示例吗?@cyber谢谢您的回复。我的屏幕打印是这样的:“厄尔斯迅速行动,为一名从乌迪内斯加盟巴塞罗那后在俱乐部的三个赛季中为巴塞罗那攻入39球的球员敲定了合同。

\p>\u201cI\u2019m很高兴加盟阿森纳,这家俱乐部有一位伟大的教练,一支出色的球员阵容,S\xe1nchez说:“世界各地的巨大支持和伦敦的一个伟大体育场,期待着与我的新队友见面,并在英超和冠军联赛中为阿森纳效力。”。我会尽我最大的努力去帮助阿森纳,我想做一个…“你有没有尝试过在API调用中添加format=json参数,以使数据以更计算机可读的形式返回?”Ben没有。确切的语法是什么?感谢您的有效载荷指令……”格式“:“json”