http://blog.csdn.net/pipisorry/article/details/46619179
Re module matching rules see: http://blog.csdn.net/pipisorry/article/details/25909899
examples of Python regular expressions
When log parsing, assume the given string:
Char str = "10.10.1.1 [2015/04/22 +0800]/ab/cd/? test0=123&test2=234 xxxx "; To get 2015/04/22,/ab/cd/, and 234 equivalents from.
str = "10.10.1.1 [2015/04/22 +0800]/ab/cd/?" test0=123&test2=234 xxxx "
Print (Re.findall ("\d{4}/\d{2}/\d{2}|/\w{2}/\w{2}| (? <=test2=) \d+ ", str))
script to download files with URLLIB2, Re, OS module!/usr/bin/env python
Importurllib2
Importre
Importos
Url= ' Http://image.baidu.com/channel/wallpaper '
Read=urllib2.urlopen (URL). Read ()
Pat =re.compile (R ' src=\ ' #\ ' "//.+?. JS ">")
Urls=re.findall (Pat,read)
Fori Inurls:
Url=i.replace (' src=\ ' #\ ' "/CODE>,"). Replace (' > ', ")
Try
Iread=urllib2.urlopen (URL). Read ()
Name=os.path.basename (URL)
With open (name, ' WB ') as Jsname:
Jsname.write (Iread)
Except
Printurl, "URL error"
from:http://blog.csdn.net/pipisorry/article/details/46619179
Ref
Python module-RE module use example