import re
str = 'PHPSESSID=l8h2lma5avpi225su5i6amuo3g; path=/; secure; HttpOnly'
# 取“PHPSESSID=”与“;”之间的文本
res = re.findall(r"PHPSESSID=(.+?);",str)
print(res)
str2 ="{'Date': 'Mon, 09 Aug 2021 13:46:45 GMT', 'Server': '', 'X-Frame-Options': 'sameorigin', 'Set-Cookie': 'PHPSESSID=l8h2lma5avpi225su5i6amuo3g; path=/; secure; HttpOnly', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Cache-Control': 'private, proxy-revalidate no-transform', 'Pragma': 'private, proxy-revalidate, no-transform', 'Vary': 'Accept-Encoding,User-Agent', 'Content-Encoding': 'gzip', 'Content-Length': '1202', 'Connection': 'close', 'Content-Type': 'image/gif'}"
print(re.findall(r"'Set-Cookie': '(.+?);",str2))
print(re.findall(r"'PHPSESSID=(.+?);",str2))
Python利用正则提取两个字符串之间的值
于 2021-08-10 00:12:43 首次发布