python re.findall(rule,data),根据左右边界取值url中参数的值

import re

'''
取值postid,左边界"postid=",右边界"&"
'''
url="http://wwww.baidu.com/aspx?postid=6232&actiontip='保存成功'"
postid=re.findall(r"postid=(.*?)&",url)[0]
print(postid)
def findall_data(data,LB="",RB=""):
    rule=LB + r"(.+?)" + RB
    datalist=re.findall(rule,data)
    return  datalist
data1=findall_data(url,"postid=",'&')[0]
print(data1)

  

posted @ 2019-07-15 23:19  心痛是尾调  阅读(1198)  评论(0编辑  收藏  举报