-
In [13]: listurl = re.findall(r'http:.+\.jpg',buf) In [15]: i = 0 In [16]: for url in listurl: ....: f = open(str(i)+'.jpg','w') ....: req = urllib2.url urllib2.url2pathname urllib2.urlopen urllib2.urlparse ....: req = urllib2.urlopen(url) ....: buf = req.read() ....: f.write(buf) ....: i+=1 ls查看全部
-
In [2]: import urllib2 In [3]: req = urllib2.url urllib2.url2pathname urllib2.urlopen urllib2.urlparse In [3]: req = urllib2.urlopen('http://www.imooc.com/course/list') In [4]: buf = req.re req.read req.readline req.readlines In [4]: buf = req.read() In [6]: import re In [7]: listurl = re.findall(r'src=.+\.jpg',buf) buf buffer In [7]: listurl = re.findall(r'src=.+\.jpg',buf) In [8]: li license list listurl查看全部
-
正则表达式语法查看全部
-
In [23]: def add1(match): ....: val = match.group() ....: num = int(val)+1 ....: return str(num) ....: In [24]: str3 Out[24]: 'imooc videonum = 1000' In [25]: re.su re.sub re.subn In [25]: re.sub(r'\d+',add1,str3) Out[25]: 'imooc videonum = 1001' In [26]: str3 = 'imooc videonum = 888' In [27]: re.sub(r'\d+',add1,str3) Out[27]: 'imooc videonum = 889'查看全部
-
正则表达式语法查看全部
-
def find_start_imooc(fname): f = open(fname) for line in f: if line.startswith('imooc'): print line def find_start_end_imooc(fname): f = open(fname) for line in f: if line.startswith('imooc')\ and line[:-1].endswith('imooc'): print line find_start_imooc('imooc.txt') print "---------------------" find_start_end_imooc('imooc.txt')查看全部
-
正则表达式 re模块查看全部
-
split 之实例练习查看全部
-
sub split 方法用法查看全部
-
re search,findall的用法查看全部
-
python第一个正则表达式查看全部
-
利用别名引用分组()中匹配的字符集查看全部
-
re.match(r'<([\w]+>)[\w]+</\1','<book>python</book>') 结果是'<book>python</book>' 其中\1表示的是()中匹配的字符集查看全部
-
特殊字符匹配规则查看全部
-
单个字符匹配规则查看全部
举报
0/150
提交
取消