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
wyy
V2EX  ›  Python

Python 爬虫中怎么讲 url 地址转义为文件名?

  •  
  •   wyy · 2018-03-15 11:08:03 +08:00 · 3449 次点击
    这是一个创建于 2228 天前的主题,其中的信息可能已经有所发展或是发生改变。
    7 条回复    2018-03-15 17:34:31 +08:00
    julyclyde
        1
    julyclyde  
       2018-03-15 11:09:05 +08:00
    什么文件的名?
    wyy
        2
    wyy  
    OP
       2018-03-15 11:10:48 +08:00   ❤️ 1
    urllib 中的 urlencode 就可以了,注意要用字典的形式作为输入 value
    wyy
        3
    wyy  
    OP
       2018-03-15 11:11:21 +08:00
    @julyclyde windows 系统中合法的文件名
    tarekyoog
        4
    tarekyoog  
       2018-03-15 11:51:04 +08:00 via Android
    url.split('/')[-1]
    netChen
        5
    netChen  
       2018-03-15 11:56:56 +08:00
    网址中的‘.’在 Windows 系统中应该不能做文件名
    binux
        6
    binux  
       2018-03-15 12:01:05 +08:00
    你要自己定一个转义规则
    Arthur2e5
        7
    Arthur2e5  
       2018-03-15 17:34:31 +08:00 via Android
    @netChen 当然可以。你下载个 bash-4.4.tar.gz 试试?


    @wyy urlencode 按 URL 合法性的会错过冒号之类一堆东西,闭着眼睛直接搞的又嫌浪费路径长度…还是需要自己列字符就是
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2904 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 13:37 · PVG 21:37 · LAX 06:37 · JFK 09:37
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.