Python regular expression summary

高洛峰
Release: 2017-03-08 11:08:48
Original
1234 people have browsed it

search(pattern, string, flags=0): Find a match in a string

finddall(pattern, string, flags=0): Find a match and return a list of all matching parts

sub(pattern, repl, string, count=0, flags=0): Replace the part of the string that matches the regular expression with other values ​​

split(pattern, string, maxsplit=0, flags=0): Split the string according to the match, Returns a list of split strings

import urllibimport re

req = urllib.urlopen('http://www.imooc.com/course/list')

buf = req.read()
listurl = re.findall(r'http:.+\.jpg', buf)print listurl

i = 0for url in listurl:
    f = open(str(i) + '.jpg', 'w')
    req = urllib.urlopen(url)
    buf = req.read()
    f.write(buf)
    i += 1
Copy after login


The above is the detailed content of Python regular expression summary. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!