案例1从固定字符串中进行提取
import re data ='''{'WWW-Authenticate': 'Basic realm="13FFF07B-948F-4654-8DDF-72680B6EE312"', 'Content-Length': '0', 'Date': 'Wed, 07 Aug 2019 06:42:25 GMT'}'''; result= re.findall("realm=\"[^\s]+\"",data); print str(result[0]).split("=")[1];
案例2=从返回参数中进行提取
import requests,re,json url = 'http://www.baidu.com' data = requests.post(url);#对百度URL进行post请求 result = data.headers;#拿到请求返回头 result_json=json.dumps(str(result)); res = re.findall(''' 'Content-Length': '(.+?)',''', result_json); print res;
来源:https://www.cnblogs.com/zh718594493/p/12350368.html