繁体   English   中英

如何从Python响应中提取文本,响应格式为text / html

[英]How to extract a text from Python response , the response format is text/html

我正在使用Python请求模块,对于API执行,响应以text / html格式显示。 我需要从响应中提取特定的文本。

{'Cache-Control': 'must-revalidate', 'Content-Type': 'text/html; charset=UTF-8', 'Date': 'Thu, 16 May 2019 01:57:47 GMT', 'Expires': 'Sat, 26 Jul 1997 05:00:00 GMT', 'Pragma': 'no-cache', 'Server': 'Apache', 'Set-Cookie': 'targetValue-fox=a%3X4%3F%7vu%4t0%3Bs%3A32%3A%34242342jkjk2342342kj42%22%3G%9K; expires=Thu, 16-May-2019 03:57:47 GMT;'Connection': 'keep-alive'}

我需要提取Set-Cookie的值。 请让我知道我们该怎么做。

从字典的内容来看,实际上看起来像标题,如果是,则使用req.headers将它们放入字典中

import requests
req = requests.get(.....)
resp = req.headers

然后,您可以从resp字典中提取密钥Set-Cookie的值

print(resp.get("Set-Cookie"))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM