求大佬帮助
import urllib.requestimport os
def url_open(url):
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36')
response = urllib.request.urlopen(url)
html = response.read()
print(url)
return html
def get_page(url):
html = url_open(url).decode('utf-8')
a = html.find('current-comment-page') + 23
b = html.find(']',a)
print(html)
return html
def find_imgs(url):
url_open(url).decode('stf-8')
img_addrs = []
a = html.find('img style=')
while a != -1:
b = html.find('.jpg',a,a+255)
if b != -1:
img_addrs.append(html)
else:
b = a + 9
a = html.find('img style=',b)
for each in img_addrs:
print(each)
def save_imgs(folder,img_addrs):
pass
def download_mm(floder='OOXX',pages=10):
os.mkdir(floder)
os.chdir(floder)
url = 'http://jandan.net/ooxx/'
page_num =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()
urllib.error.HTTPError: HTTP Error 403: Forbidden代码报这个错误是什么意思啊,是无法访问吗? 403一般代表服务器拒绝你的访问,也就是你被反爬拦截了
有关具体解释请看
https://man.ilovefishc.com/pageHTML5/HTTP.html 爬虫有风险,如果你一次性爬取大量的图片,对方会知道会直接静止你IP访问该网站。要么你就是调时间每几秒爬取一张图片或者去搜索其他IP进行访问
海皇 发表于 2020-8-11 11:48
爬虫有风险,如果你一次性爬取大量的图片,对方会知道会直接静止你IP访问该网站。要么你就是调时间每几秒爬 ...
IP代理了解一下~
页:
[1]