|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.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(page_url):
pass
def save_img(img_addrs):
pass
def download_mm(folder = 'OOXX',pages = 10):
if not os.path.exists(folder):
os.mkdir(folder)
os.chdir(folder)
url = 'http://jandan.net/ooxx'
page_name = 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_img(folder,img_addrs)
if __name__ == '__main__':
download_mm()
报错的信息是这样的:
Traceback (most recent call last):
File "D:/python/代码/jiandan_net_mm.py", line 39, in <module>
download_mm()
File "D:/python/代码/jiandan_net_mm.py", line 30, in download_mm
page_name = get_page(url)
File "D:/python/代码/jiandan_net_mm.py", line 8, in get_page
response = urllib.request.urlopen(url)
File "D:\python\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "D:\python\lib\urllib\request.py", line 471, in open
response = meth(req, response)
File "D:\python\lib\urllib\request.py", line 581, in http_response
'http', request, response, code, msg, hdrs)
File "D:\python\lib\urllib\request.py", line 503, in error
result = self._call_chain(*args)
File "D:\python\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "D:\python\lib\urllib\request.py", line 686, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "D:\python\lib\urllib\request.py", line 471, in open
response = meth(req, response)
File "D:\python\lib\urllib\request.py", line 581, in http_response
'http', request, response, code, msg, hdrs)
File "D:\python\lib\urllib\request.py", line 509, in error
return self._call_chain(*args)
File "D:\python\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "D:\python\lib\urllib\request.py", line 589, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
请教各位大声这是怎么回事呢,我自己的电脑访问www.jiandan.net这个网址是没有问题的
|
|