Python查找并捕获字符串(模式匹配)

2018/03/28 python 共 324 字,约 1 分钟
import re

formhashRe = re.search('name="formhash" value="(\w+?)"', response.text, re.DOTALL)
refererRe = re.search('name="referer" value="(.*?)"', response.text, re.DOTALL)
print(f"formhashRe = {formhashRe}, refererRe = {refererRe}")
if formhashRe:
    formhash = formhashRe.group(1)
else:
    formhash = ""
if refererRe:
    referer = refererRe.group(1)
else:
    referer = ""

文档信息

Search

    Table of Contents