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

网络视频 url 如何判断是否有效?

  •  
  •   viiii · Jan 7, 2020 · 3855 views
    This topic created in 2305 days ago, the information mentioned may be changed or developed.

    最近爬了一些视频链接练手,爬下来之后,发现部分链接是无效的(无法播放),于是打算筛选一遍,保留有效链接。 在筛选时,发现通过响应码或者 html 内容都无法准确判断某条链接是否有效,请问该从哪里下手进行鉴别呢?

    视频链接示例: http://abc.cdn.baidu.net/upic/2017/07/28/00/BMjAxNzA3MjgwMcxNDM4MzlfMl8z.mp4

    7 replies    2020-01-08 11:46:14 +08:00
    kernelpanic
        2
    kernelpanic  
       Jan 7, 2020
    curl -o - -H 'Range: bytes=0-16' -sI '***.mp4' |grep 'Content-Type'|cut -d ' ' -f2
    106npo
        3
    106npo  
       Jan 7, 2020 via Android
    ffmpeg 也行(
    airdrop
        4
    airdrop  
       Jan 7, 2020 via iPhone
    请求视频的 range bytes=0-1,检查 response 里的 content length
    xiaoz
        5
    xiaoz  
       Jan 7, 2020 via Android
    curl 只请求 header 部分,根据返回状态吗来判断。
    airdge
        6
    airdge  
       Jan 7, 2020
    requests.head(url).status_code
    viiii
        7
    viiii  
    OP
       Jan 8, 2020
    @airdge 多谢提示,已经搞定!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2490 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 07:56 · PVG 15:56 · LAX 00:56 · JFK 03:56
    ♥ Do have faith in what you're doing.