|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- import urllib.request
- import os
- def get_page(url):
- req = urllib.request.Request(url)
- req.add_header('User-Agent','Mozilla/5.0 (Windows NT 5.1; rv:47.0) Gecko/20100101 Firefox/47.0')
- response = urllib.request.urlopen(url)
- html = response.read().decode('utf-8')
- a = html.find('current-comment-page')+23
- b = html.find(']',a)
-
- print(html[a:b])
- def find_imgs(url):
- pass
- def save_imgs(folder,img_addrs):
- pass
- def download_mm(folder='OOXX',pages = 10):
- os.mkdir(folder)
- os.chdir(folder)
- url = "http://jandan.net/ooxx"
- page_num = int(get_page(url))
- for i in range(pages):
- page_num -= i
- page_url = url +'page-'+str(page_num)+'#comments'
- img_addrs = find_imgs(page_url)
- save_imgs(folder,img_addrs)
- if __name__=='__main__':
- download_mm()
-
复制代码
- Traceback (most recent call last):
- File "E:\lorraine\01\Python\爬妹子图00.py", line 38, in <module>
- download_mm()
- File "E:\lorraine\01\Python\爬妹子图00.py", line 29, in download_mm
- page_num = int(get_page(url))
- File "E:\lorraine\01\Python\爬妹子图00.py", line 7, in get_page
- response = urllib.request.urlopen(url)
- File "C:\Python34\lib\urllib\request.py", line 161, in urlopen
- return opener.open(url, data, timeout)
- File "C:\Python34\lib\urllib\request.py", line 470, in open
- response = meth(req, response)
- File "C:\Python34\lib\urllib\request.py", line 580, in http_response
- 'http', request, response, code, msg, hdrs)
- File "C:\Python34\lib\urllib\request.py", line 502, in error
- result = self._call_chain(*args)
- File "C:\Python34\lib\urllib\request.py", line 442, in _call_chain
- result = func(*args)
- File "C:\Python34\lib\urllib\request.py", line 685, in http_error_302
- return self.parent.open(new, timeout=req.timeout)
- File "C:\Python34\lib\urllib\request.py", line 470, in open
- response = meth(req, response)
- File "C:\Python34\lib\urllib\request.py", line 580, in http_response
- 'http', request, response, code, msg, hdrs)
- File "C:\Python34\lib\urllib\request.py", line 508, in error
- return self._call_chain(*args)
- File "C:\Python34\lib\urllib\request.py", line 442, in _call_chain
- result = func(*args)
- File "C:\Python34\lib\urllib\request.py", line 588, in http_error_default
- raise HTTPError(req.full_url, code, msg, hdrs, fp)
- urllib.error.HTTPError: HTTP Error 503: Service Temporarily Unavailable
复制代码 |
|