V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Oct 11, 2015 · 4546 views
    This topic created in 3851 days ago, the information mentioned may be changed or developed.

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

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

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

    21 replies    2015-10-12 13:56:53 +08:00
    dqh3000
        1
    dqh3000  
       Oct 11, 2015
    不用 Beautiful Soup?
    pkuphy
        2
    pkuphy  
    PRO
       Oct 11, 2015
    Python requests + BeautifulSoup
    rming
        3
    rming  
       Oct 11, 2015
    pyquery 也很好
    AWWBWG
        4
    AWWBWG  
       Oct 11, 2015
    小 H 图是学习 Python 的动力~
    C1ara
        5
    C1ara  
    OP
       Oct 11, 2015
    @dqh3000 _(:3_/ 今天才开始接触 python 还没装 BS ……
    Tink
        6
    Tink  
    PRO
       Oct 11, 2015 via iPhone
    就这么简单的正则不用上那么重的东西
    imn1
        7
    imn1  
       Oct 11, 2015
    <img[^>]+src="([^"]+)"
    seiwev
        8
    seiwev  
       Oct 11, 2015
    cd C:\beautifulsoup4-4.4.1
    C:\Python27\python setup.py install
    linghutf
        9
    linghutf  
       Oct 11, 2015 via Android
    nodejs cheerio ,我就是这样下图片的之前用 python 可惜文档比较烦
    humanfans
        10
    humanfans  
       Oct 11, 2015
    当年批量下云图 就是用 linux 下的 bash 用的 wget...
    C1ara
        11
    C1ara  
    OP
       Oct 11, 2015
    @seiwev 装不上 BS 给跪了……改了环境变量也没用 T T
    一直显示 no commands supplied
    gimp
        12
    gimp  
       Oct 11, 2015
    str.split('"')
    iamnuomi
        13
    iamnuomi  
       Oct 11, 2015
    这不就是该用正则的东西吗
    ClutchBear
        14
    ClutchBear  
       Oct 12, 2015
    bs4
    然后
    soup.get('src')
    就出来了啊
    fy
        15
    fy  
       Oct 12, 2015
    @AWWBWG - - 尼玛 总是看到有人学了 py 之后就去下小黄图,当年的我怎么没有这么机智
    C1ara
        16
    C1ara  
    OP
       Oct 12, 2015
    @ClutchBear 装了两个小时也没装上 BS ……给跪
    neutrino
        17
    neutrino  
       Oct 12, 2015 via Android
    strstr(URL, 5, strlen(URL-6))
    macroideal
        18
    macroideal  
       Oct 12, 2015
    xpath
    C1ara
        19
    C1ara  
    OP
       Oct 12, 2015
    @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  
       Oct 12, 2015
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3397 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 60ms · UTC 12:29 · PVG 20:29 · LAX 05:29 · JFK 08:29
    ♥ Do have faith in what you're doing.