python Http响应包含\ n字符

问题描述

我正在使用python HTTP Request程序包来进行HTTP get调用。这个工作正常,我可以得到回应。 但是响应包含HTML标记间的\ n。我验证了URL的源代码,并且确实在HTML代码之间存在新行,但这在呈现HTML时不会造成损害,但是在HTTP响应中,当我尝试解析HTML时,会添加这些新行。

with requests.get(url,**get_req_parameters(proxyDict)) as req:
                http_response_code = req.status_code
                html_content = req.content

HTML code:

<!doctype html>
<html xmlns:og="http://opengraPHProtocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml" lang="en-US"  >
  <head>
    <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <Meta name="viewport" content="initial-scale=1">

    <!-- This is Squarespace. --><!-- heitest2 -->

Http响应添加\ n

<!doctype html>\n<html xmlns:og="http://opengraPHProtocol.org/schema/" xmlns:fb="http://www.facebook.com/2008/fbml" lang="en-US"  >\n <head>\n    <Meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">\n 

我在HTTP响应内容中不需要这些换行符(\ n)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)