朱皮特的博客 自由的飞翔

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

2018-03-28
朱皮特
阅读量:

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 = ""

Comments

Content