import re
def add1(match):
val=match.group()
num=int(val)+1
return str(num)
str3='imooc videonum = 1000'
x=re.sub(r'\d+',add1,str3)
开始定义的函数,match值从哪来啊
def add1(match):
val=match.group()
num=int(val)+1
return str(num)
str3='imooc videonum = 1000'
x=re.sub(r'\d+',add1,str3)
开始定义的函数,match值从哪来啊
2018-01-21
建议遇到问题的同学先修改以下三处代码
listurl = re.findall(r'//.+?\.jpg*', buf) #匹配src中的内容
f = open('D:/picture/' + str(i) + '.jpg', 'wb') #将图片存到D盘下的picture中
req = urllib2.urlopen('http:'+url) #爬取图片
listurl = re.findall(r'//.+?\.jpg*', buf) #匹配src中的内容
f = open('D:/picture/' + str(i) + '.jpg', 'wb') #将图片存到D盘下的picture中
req = urllib2.urlopen('http:'+url) #爬取图片
2018-01-18
i = 0
old_url = ''
for _url in listurl:
f = open(str(i)+'.jpg','wb')
url = 'http:'+_url
if url == old_url:
continue
old_url = url
#print (url,'')
req = request.urlopen(url)
buf = req.read()
f.write(buf)
i += 1
f.close()
print ('download %s '%(i))
old_url = ''
for _url in listurl:
f = open(str(i)+'.jpg','wb')
url = 'http:'+_url
if url == old_url:
continue
old_url = url
#print (url,'')
req = request.urlopen(url)
buf = req.read()
f.write(buf)
i += 1
f.close()
print ('download %s '%(i))
2018-01-07
Python3.6版本
from urllib import request
import re
url = 'https://www.imooc.com/course/list'
req = request.urlopen(url)
buf = req.read()
buf = buf.decode('utf-8')
listurl = re.findall(r'\/\/img.+?\.jpg',buf)
#for _url in listurl:
# print(_url)
from urllib import request
import re
url = 'https://www.imooc.com/course/list'
req = request.urlopen(url)
buf = req.read()
buf = buf.decode('utf-8')
listurl = re.findall(r'\/\/img.+?\.jpg',buf)
#for _url in listurl:
# print(_url)
2018-01-07