推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
O21
V2EX  ›  Python

Python 处女座 源码,抓取豆瓣妹子图片,卡壳了。。求助大神

  •  
  •   O21 ·
    ShenXuGongZi · Jul 14, 2014 · 7942 views
    This topic created in 4340 days ago, the information mentioned may be changed or developed.
    代码:


    目前路径是定死的。。

    我想用
    img_LuJ = raw_input("路径:") 来获取路径
    然后体现在
    68行
    download_img = urllib.urlretrieve(imgurl,'/home/Hang/文档/PythonEX/Doubanimg/%s.jpg'%img_num)
    download这个函数里面

    download_img = urllib.urlretrieve(imgurl,'%r/%s.jpg'%(img_LuJ,img_num))

    这样写。。 可是没用。。 他会获取到
    '/home/xxx'/'sss.jpg 路径上有引号。。。 我很无语。
    Supplement 1  ·  Jul 14, 2014
    @paulw54jrn
    @izoabr
    @77421
    哈哈 感谢回复 我已经搞定啦~~~~
    方法
    引入 os
    import os
    img_LuJ = raw_input("路径:".decode('utf-8'))
    img_LuJ2 = os.path.abspath(img_LuJ)

    然后在函数里面

    download_img = urllib.urlretrieve(imgurl,img_LuJ2 + '/%s.jpg'%img_num)

    这样就木有问题啦~~ 哈哈哈啊哈哈哈哈哈哈~~~~


    题外话。。。 为什么不让我回复了。。。V2ex怎么设置的啊。。我没灌水。。
    "创建新回复过程中遇到一些问题:
    你回复过于频繁了,请稍等 1800 秒之后再试"
    Supplement 2  ·  Jul 15, 2014
    成品源码: http://www.v2ex.com/t/122642

    欢迎指教 嘿嘿?
    23 replies    2014-08-01 11:31:46 +08:00
    O21
        1
    O21  
    OP
       Jul 14, 2014
    =,= 写的有点乱。。新手,,请各位海涵~~
    77421
        2
    77421  
       Jul 14, 2014
    用正则。。
    O21
        3
    O21  
    OP
       Jul 14, 2014
    @77421 木有太看懂。。是用正则获取用户输入路径吗?
    izoabr
        4
    izoabr  
       Jul 14, 2014
    为什么是3个引号?
    Fotix
        5
    Fotix  
       Jul 14, 2014
    一看就是抓晒组的,果不其然
    O21
        6
    O21  
    OP
       Jul 14, 2014
    @izoabr
    错误是这个
    IOError: [Errno 2] No such file or directory: u"'/home/o21/img'/p8406921.jpg"
    izoabr
        7
    izoabr  
       Jul 14, 2014
    @O21 这个IOError是哪行报出来的?
    你试试先拼接目标路径+文件名到一个变量,不用%号去拼
    paulw54jrn
        8
    paulw54jrn  
       Jul 14, 2014
    @O21
    错误:
    IOError: [Errno 2] No such file or directory: u'/home/o21/\u6587\u6863/PythonEX/Doubanimg/p1616253.jpg'
    检查下Unicode的问题
    O21
        9
    O21  
    OP
       Jul 14, 2014
    @izoabr 我这样写了。
    img_LuJ = raw_input("路径:".decode('utf-8'))

    download_img = urllib.urlretrieve(imgurl,img_LuJ + '/%s.jpg'%img_num)

    然后报错
    IOError: [Errno 2] No such file or directory: u'/home/o21/img/p1611237.jpg'
    paulw54jrn
        10
    paulw54jrn  
       Jul 14, 2014
    把下载路径改成 '/tmp/%s.jpg' % img_num 用做测试的话,程序可以跑起来

    paul@PaulMBP:~/Desktop$ ipython test.py
    ##################################################
    本程序主要采集豆瓣<请不要害羞>小组的图片
    ##################################################
    采集前需要输入代理服务器地址,这样可以防止被豆瓣屏蔽.
    推荐一个代理地址: http://cn-proxy.com/
    只需要输入服务器地址以及端口号,不需要输入http
    例子:127.0.0.1:8080
    ##################################################
    请输入采集代理服务器:121.10.120.135:8001
    请输入采集页码数:1
    http://img3.douban.com/view/group_topic/large/public/p16112371.jpg
    http://img3.douban.com/view/group_topic/large/public/p16112380.jpg
    程序采集完成
    O21
        11
    O21  
    OP
       Jul 14, 2014
    @paulw54jrn 我这次木有用中文,也报错。。我楼上写了。。 很郁闷。
    paulw54jrn
        12
    paulw54jrn  
       Jul 14, 2014
    这样试试?

    file = "/home/o21/img/%s.jpg" % img_num
    try:
    download_img = urllib.urlretrieve(imgurl,file)
    except IOError:
    os.mkdir(file.[:file.rfind("/")])
    paulw54jrn
        13
    paulw54jrn  
       Jul 14, 2014
    唔..偷懒没用gist..
    缩进乱了..不过你懂的..
    kawaiiushio
        14
    kawaiiushio  
       Jul 15, 2014
    求成品分享
    O21
        15
    O21  
    OP
       Jul 15, 2014
    @kawaiiushio 在这里下载吧 HOHO http://162.244.92.122/DouBanMZ.zip
    WhyLiam
        16
    WhyLiam  
       Jul 15, 2014
    和我一样,我也前天写了抓 害羞组 图片的程序。同道中人啊
    但是写的比你简单多了。。。
    已经抓了近1700页了
    eslizn
        17
    eslizn  
       Jul 15, 2014
    我是来看害羞组的
    C0VN
        18
    C0VN  
       Jul 15, 2014
    哈哈,我写过抓取虎扑相册的工具。起初也是为了抓妹子图。

    http://hualbum.duapp.com/
    puyo
        19
    puyo  
       Jul 15, 2014
    可以加入多线程,速度要快一些。
    dingyaguang117
        20
    dingyaguang117  
       Jul 15, 2014
    至少 socket 的timeout 要加吧,不然死都不知道怎么死的
    sujin190
        21
    sujin190  
       Jul 15, 2014
    看来写过多注释也有不利的时候。。
    shyrock
        22
    shyrock  
       Jul 15, 2014
    请教解决中文报错那段是啥意思?
    horizon
        23
    horizon  
       Aug 1, 2014
    为什么要用代理?在header里直接加入cookies就可以了啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   989 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 5414617a · 63ms · UTC 22:15 · PVG 06:15 · LAX 15:15 · JFK 18:15
    ♥ Do have faith in what you're doing.