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