鱼C论坛

 找回密码
 立即注册
查看: 1690|回复: 4

[已解决]56讲爬妹子图的问题,急求,运行不下去了

[复制链接]
发表于 2018-3-28 09:55:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 fan1993423 于 2018-3-28 10:09 编辑

import urllib.request as ur
import os
def urlopen(url):
    req=ur.Request(url)
    req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.90 Safari/537.36 2345Explorer/9.2.1.17116')
    response=ur.urlopen(req)
    html=response.read()
    print(url)
    return html
def getpage(url):
    html=urlopen(url).decode('utf-8')
    a=html.find('current-comment-page')+23
    b=html.find(']',a)
    return html[a:b]

def findimg(url):
    html=urlopen(url).decode('utf-8')
    imgadr=[]

    a=html.find('img src=')
    while a!=-1:
        b=html.find('.jpg',a,a+255)
        if b!=-1:
            imgadr.append(html[a+9:b+4])
        else:
            b=a+9
        a=html.find('img src=',b)
    for each in imgadr:
        print(each)
        
        
def saveimg(folder,img):
    pass
def meizi(folder='X',pages=30):
  
    url='http://jandan.net/ooxx/'
    pagenum=int(getpage(url))
    for i in range(pages):
        pagenum-=i
        pageurl=url+'page-'+str(pagenum)+'#comments'
        img=findimg(pageurl)
        saveimg(folder,img)
if __name__=='__main__':
    meizi()
   
这是按小甲鱼老师的视频写的代码,但是出现以下错误,我反复查看了代码,跟小甲鱼没有差别啊,有没有谁能告诉我哪里有问题,急求
http://jandan.net/ooxx/
http://jandan.net/ooxx/page-51#comments
http://jandan.net/ooxx/page-50#comments
http://jandan.net/ooxx/page-48#comments
http://jandan.net/ooxx/page-45#comments
http://jandan.net/ooxx/page-41#comments
http://jandan.net/ooxx/page-36#comments
http://jandan.net/ooxx/page-30#comments
http://jandan.net/ooxx/page-23#comments
http://jandan.net/ooxx/page-15#comments
http://jandan.net/ooxx/page-6#comments
Traceback (most recent call last):
  File "C:/Users/zd/Desktop/meizi.py", line 44, in <module>
    meizi()
  File "C:/Users/zd/Desktop/meizi.py", line 41, in meizi
    img=findimg(pageurl)
  File "C:/Users/zd/Desktop/meizi.py", line 17, in findimg
    html=urlopen(url).decode('utf-8')
  File "C:/Users/zd/Desktop/meizi.py", line 6, in urlopen
    response=ur.urlopen(req)
  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 469, in open
    response = meth(req, response)
  File "C:\Python34\lib\urllib\request.py", line 579, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python34\lib\urllib\request.py", line 507, in error
    return self._call_chain(*args)
  File "C:\Python34\lib\urllib\request.py", line 441, in _call_chain
    result = func(*args)
  File "C:\Python34\lib\urllib\request.py", line 587, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found   
最佳答案
2018-3-28 11:31:03
fan1993423 发表于 2018-3-28 11:24
能告诉我这个变化的意思嘛?另外html[a:b]又是什么意思?

小甲鱼的代码你不用看了,早就不能用了
我让你看我这个文章的代码,因为简单的网页结构变了
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-3-28 10:37:37 | 显示全部楼层
妹子图有反爬虫 http://bbs.fishc.com/thread-107034-1-1.html
自己看文章,然后,我前几天刚写玩这个爬虫,简单的JS就变了,看评论里面有代码需要改的地方
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-28 11:24:49 | 显示全部楼层
gopythoner 发表于 2018-3-28 10:37
妹子图有反爬虫 http://bbs.fishc.com/thread-107034-1-1.html
自己看文章,然后,我前几天刚写玩这个爬虫 ...

能告诉我这个变化的意思嘛?另外html[a:b]又是什么意思?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-3-28 11:31:03 | 显示全部楼层    本楼为最佳答案   
fan1993423 发表于 2018-3-28 11:24
能告诉我这个变化的意思嘛?另外html[a:b]又是什么意思?

小甲鱼的代码你不用看了,早就不能用了
我让你看我这个文章的代码,因为简单的网页结构变了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-3-28 11:35:16 | 显示全部楼层
gopythoner 发表于 2018-3-28 11:31
小甲鱼的代码你不用看了,早就不能用了
我让你看我这个文章的代码,因为简单的网页结构变了

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-3 08:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表