The RE module provides an engine interface for the Zheng expression, which allows your re string to be mutated into an object and used for matching, which is a high efficiency. Let's take a look at some examples.
The following is a small script that I wrote similar to reptiles, for your reference
#!/usr/bin/python
# Coding=utf-8
Import Urllib
Import re
Import OS
Def gethtmldata ():
Return Urllib.urlopen ("http://news.cnblogs.com/n/93182"). Read ()
Def getimagelist ():
#reg1 = Re.compile (R ' (http.*jpg) \ "T ')
REG2 = Re.compile (R ' src=\ "(http.*jpg) \")
Text = Gethtmldata ()
#list1 = Reg1.findall (text)
List2 = Reg2.findall (text)
x = 30
Print OS.GETCWD ()
For IMAGEURL in List2:
Print ImageUrl
Urllib.urlretrieve (IMAGEURL, R "jpg/%s.jpg"% x)
X+=1
GetImageList ()
REG2 = Re.compile (R ' src=\ "(http.*jpg) \") matches "src=" at the beginning, "The end of the character, the http.*jpg in parentheses is the content to be obtained, and such an expression is compiled into an object
In the example, the "http://news.cnblogs.com/n/93182" content in the page is attached. The function of this little script is to find the high-definition picture in the page and download it to the JPG folder of the current directory.
This article comes from "on the road ... "Blog, be sure to keep this provenance http://yongbird.blog.51cto.com/7554149/1548471
Python Regular expression 1