马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import os
def url_open(url):
req = urllib.request.Request(url)
req.add_header('user-agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36')
response = urllib.request.urlopen(req)
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)
return html[a:b]
def find_imgs(url):
html = url_open(url).decode('utf-8')
img_addrs = []
a = html.find('<img src=')
while a != -1:
b = html.find('.jpg', a, a+255)
if b != -1:
img_addrs.append.http:(html[a+9:b+4])
else:
b = a + 9
a = html.find('img src=', b)
for each in img_addrs:
print(each)
def save_imgs(folder,img_addrs):
pass
def download_mm( folder = 'girl', pages = 10):
os.mkdir(folder)
os.chdir (folder)
url = 'https://www.zxs51.com/mnxz/'
page_name = int(get_page(url))
for i in range(pages):
page_num = -i
page_url = url + 'page-' + str(page_num) + '#comment'
img_addrs = find_imgs(page_url)
save_imgs(folder,img_addrs)
if __name__ =='__main__':
download_mm()
运行结果========== RESTART: /Users/nidelu/Desktop/python/给爷爬/爬虫4/妹子图.py/妹子图.py =========
https://www.zxs51.com/mnxz/
Traceback (most recent call last):
File "/Users/nidelu/Desktop/python/给爷爬/爬虫4/妹子图.py/妹子图.py", line 57, in <module>
download_mm()
File "/Users/nidelu/Desktop/python/给爷爬/爬虫4/妹子图.py/妹子图.py", line 48, in download_mm
page_name = int(get_page(url))
ValueError: invalid literal for int() with base 10: ' lang="zh-CN">\r\n<head>\r\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\r\n<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable
请问这是怎么回事 |