V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
C1ara
V2EX  ›  Python

我就想下个图……

  •  
  •   C1ara · 2015-10-11 19:06:22 +08:00 · 3999 次点击
    这是一个创建于 3127 天前的主题,其中的信息可能已经有所发展或是发生改变。

    忽然想写个自动下图的小玩意儿 目前进度才接近分离出图链……就卡住了

    src="https://40.media.tumblr.com/235d904d7f799dfc95fdf50099652d6a/tumblr_inline_nw0i4ib1VH1snoibe_540.png"

    一行大概就长这样,后缀有 jpg/png/gif 三种,总共十几行
    求问怎么去掉前缀单独把链接拉出来?
    非常感谢

    21 条回复    2015-10-12 13:56:53 +08:00
    dqh3000
        1
    dqh3000  
       2015-10-11 19:13:21 +08:00
    不用 Beautiful Soup?
    pkuphy
        2
    pkuphy  
       2015-10-11 19:17:24 +08:00
    Python requests + BeautifulSoup
    rming
        3
    rming  
       2015-10-11 19:19:55 +08:00
    pyquery 也很好
    AWWBWG
        4
    AWWBWG  
       2015-10-11 19:21:27 +08:00
    小 H 图是学习 Python 的动力~
    C1ara
        5
    C1ara  
    OP
       2015-10-11 19:21:33 +08:00
    @dqh3000 _(:3_/ 今天才开始接触 python 还没装 BS ……
    Tink
        6
    Tink  
       2015-10-11 19:23:44 +08:00 via iPhone
    就这么简单的正则不用上那么重的东西
    imn1
        7
    imn1  
       2015-10-11 19:26:32 +08:00
    <img[^>]+src="([^"]+)"
    seiwev
        8
    seiwev  
       2015-10-11 19:29:49 +08:00
    cd C:\beautifulsoup4-4.4.1
    C:\Python27\python setup.py install
    linghutf
        9
    linghutf  
       2015-10-11 20:24:53 +08:00 via Android
    nodejs cheerio ,我就是这样下图片的之前用 python 可惜文档比较烦
    humanfans
        10
    humanfans  
       2015-10-11 20:44:22 +08:00
    当年批量下云图 就是用 linux 下的 bash 用的 wget...
    C1ara
        11
    C1ara  
    OP
       2015-10-11 22:05:37 +08:00
    @seiwev 装不上 BS 给跪了……改了环境变量也没用 T T
    一直显示 no commands supplied
    gimp
        12
    gimp  
       2015-10-11 22:38:28 +08:00
    str.split('"')
    iamnuomi
        13
    iamnuomi  
       2015-10-11 23:37:16 +08:00
    这不就是该用正则的东西吗
    ClutchBear
        14
    ClutchBear  
       2015-10-12 01:04:35 +08:00
    bs4
    然后
    soup.get('src')
    就出来了啊
    fy
        15
    fy  
       2015-10-12 01:54:08 +08:00
    @AWWBWG - - 尼玛 总是看到有人学了 py 之后就去下小黄图,当年的我怎么没有这么机智
    C1ara
        16
    C1ara  
    OP
       2015-10-12 07:41:27 +08:00
    @ClutchBear 装了两个小时也没装上 BS ……给跪
    neutrino
        17
    neutrino  
       2015-10-12 08:38:09 +08:00 via Android
    strstr(URL, 5, strlen(URL-6))
    macroideal
        18
    macroideal  
       2015-10-12 09:50:27 +08:00
    xpath
    C1ara
        19
    C1ara  
    OP
       2015-10-12 10:50:10 +08:00
    @gimp 感谢

    但是问题又来了……随手写的时候(无 class/init/self ) str.split 是可行的 脑袋一热准备整理下结果:
    class downloader(string):
    TypeError: Error when calling the metaclass bases
    module.__init__() takes at most 2 arguments (3 given)
    谷歌出来是 module/class 弄混了,改成
    class downloader(string.string):
    AttributeError: 'module' object has no attribute 'string'
    还是错误 再试 import string from string
    仍然错误
    _(:3 奶奶的我不要格式了!
    znoodl
        21
    znoodl  
       2015-10-12 13:56:53 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   933 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:24 · PVG 07:24 · LAX 16:24 · JFK 19:24
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.