已采纳回答 / seU
前面15分钟的两节re模块你一定没看,已经讲的很清楚了match()是re模块的函数,根据匹配规则匹配对应的字符串group()函数,是返回匹配成功的字符串
2016-09-01
In [104]: i = 0
In [105]: for url in listurl:
...: f = open(str(i) + '.jpg', 'wb')
...: req = urllib.request.urlopen(url)
...: buf = req.read()
...: f.write(buf)
...: i+=1
...:
感谢老师!写了人生中第一个爬虫!!!
In [105]: for url in listurl:
...: f = open(str(i) + '.jpg', 'wb')
...: req = urllib.request.urlopen(url)
...: buf = req.read()
...: f.write(buf)
...: i+=1
...:
感谢老师!写了人生中第一个爬虫!!!
2016-08-14
Python 3.x 版本这么输入:
In [1]: import re
In [2]: import urllib.request
In [3]: req = urllib.request.urlopen('http://www.imooc.com/course/list')
In [4]: buf = req.read()
In [5]: buf = buf.decode('utf-8')
In [6]: listurl = re.findall(r'src=.+\.jpg', buf)
In [1]: import re
In [2]: import urllib.request
In [3]: req = urllib.request.urlopen('http://www.imooc.com/course/list')
In [4]: buf = req.read()
In [5]: buf = buf.decode('utf-8')
In [6]: listurl = re.findall(r'src=.+\.jpg', buf)
2016-08-14
Python 3.x 版本请这么输入:
import urllib.request
req = urllib.request.urlopen('http://www.imooc.com/course/list')
buf = req.read()
import urllib.request
req = urllib.request.urlopen('http://www.imooc.com/course/list')
buf = req.read()
2016-08-14