我想转换包含html
标记的字符串,以便我可以使用selectors
来提取少量信息。我在html
回复中收到此json
。我使用了HTMLParser
,但收到的错误为exceptions.TypeError: cannot create weak reference to 'unicode' object
我的代码是:
sel = Selector(response)
jsonresponse = json.loads(response.body_as_unicode())
hello= jsonresponse["html"].encode('ascii','ignore')
h = HTMLParser.HTMLParser()
world=h.unescape(hello)
sel1 = Selector(world)
答案 0 :(得分:0)
我得到了答案:
我只需在使用text
时提及Selectors
,以防案例响应为字符串。
sel = Selector(response)
jsonresponse = json.loads(response.body_as_unicode())
hello= jsonresponse["html"].encode('ascii','ignore')
sel1 = Selector(text=hello)