from 《Python 爬虫开发 从入门到实战》谢乾坤
pattern表示正则表达式,string表示原来的字符串,flags表示一些特殊功能的标志。
findall的结果是一个列表,包含了所有匹配到的结果。如果没有匹配到结果,就会返回空列表。
from re.py
def findall(pattern, string, flags=0):"""Return a list of all non-overlapping matches in the string.返回字符串中所有不重叠匹配项的列表。If one or more capturing groups are present in the pattern, returna list of groups; this will be a list of tuples if the patternhas more than one group.如果模式中存在一个或多个捕获组,则返回组列表; 这将是一个元组列表,如果模式有一个以上的团体。Empty matches are included in the result.空匹配项包含在结果中"""return _compile(pattern, flags).findall(string)
如:
content_extract=re.findall('(.*?) (.*?) (.*?) (.*?) (.*?)\n',content)
参考文章:Python 正则表达式