python lxml etree.tostring()为什么\r\n对&;进行编码#13;

python lxml etree.tostring()为什么\r\n对&;进行编码#13;,python,lxml,Python,Lxml,我已尝试分析: request=urllib2.request(url=”http://2012.qq.com/sports/") response=urllib2.urlopen(请求) content=response.read() uni_content=content.decode(“gb2312”,“忽略”) 腾讯=统一内容编码(“utf-8”) tecent_page=etree.HTML(tecent,parser=etree.HTMLParser(encoding='utf-8'

我已尝试分析:

request=urllib2.request(url=”http://2012.qq.com/sports/")
response=urllib2.urlopen(请求)
content=response.read()
uni_content=content.decode(“gb2312”,“忽略”)
腾讯=统一内容编码(“utf-8”)
tecent_page=etree.HTML(tecent,parser=etree.HTMLParser(encoding='utf-8'))
test_tags=tecent_page.xpath(“/html/body/div[@class='page']/div[@class='layout']/div/div[@class='bd']/ul[@class='list']/li”)
对于i,枚举中的项(test_标记):
content=etree.tostring(item,encoding=“utf-8”,pretty\u print=True)
印刷内容
为什么会出现这样的结果:

  • &13;

    ; | |

    和#13;
  • 和#13;
    为什么它有
    

    和#13在每行中。为什么?

    因为原始文档()已被删除。代码是13


    您可以使用简单的解决方法:
    tecent=uni_content.encode(“utf-8”)。替换('\r\n','\n')
    ,因为原始文档()已被删除。代码是13

    您可以使用简单的解决方法:
    tecent=uni\u content.encode(“utf-8”).replace('\r\n','\n')