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

爬取斗鱼网站 lol 分区时,获取的网页数据是经过压缩的,尝试了几种解压方法后,得到时大量数字的无用数据。

  •  
  •   SimWit · 2019-07-25 23:49:29 +08:00 · 3718 次点击
    这是一个创建于 1708 天前的主题,其中的信息可能已经有所发展或是发生改变。

    1.爬取网页: https://www.douyu.com/g_LOL

    2.采用方法:只是初步接触爬虫,没有用额外的库。基本实现思路 :

    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
    url = 'https://www.douyu.com/g_LOL'
    
    req = request.Request(url, headers=headers)
    r = request.urlopen(req)
    buff = BytesIO(r.read())
    f = gzip.GzipFile(fileobj=buff)
    htmls = f.read().decode('utf-8')
    

    3.结果 爬取的网页中间出现了大量的数字乱码,例如:

    47 14.4 14.4s-6.447 14.4-14.4 14.4z"/><path d="M20.331 18.069c0.625 0.625 0.625 1.638 0 2.263s-1.638 0.625-2.
    

    并且,在调试到

    req = request.Request(url, headers=headers)
    

    时,弹出<string>文档,显示:</string>

     无法加载源“<string>”: Source unavailable。
    

    4.我认为可能是对爬来的数据解压方式不对,多谢帮忙!

    6 条回复    2019-07-26 14:12:48 +08:00
    baxtergu
        1
    baxtergu  
       2019-07-26 00:06:39 +08:00   ❤️ 1
    这个是 svg,多用于图标
    LengthMin
        2
    LengthMin  
       2019-07-26 00:09:20 +08:00   ❤️ 1
    简单的看了看。
    1. 这些 path 都是 svg
    2. 可以试试用 beautifulsoup
    yuzo555
        3
    yuzo555  
       2019-07-26 03:50:53 +08:00
    数字乱码 XD
    colorfulberry
        4
    colorfulberry  
       2019-07-26 08:39:04 +08:00
    react 写的,有没有加后端渲染,拿不了东西。
    learnshare
        5
    learnshare  
       2019-07-26 09:07:30 +08:00
    <path d=""> 这是 SVG,d 是绘图指令
    kygowl77
        6
    kygowl77  
       2019-07-26 14:12:48 +08:00
    是 svg 网页矢量图 可以自己写个 html 把数据放进去 自己用浏览器打开看看
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5514 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 06:39 · PVG 14:39 · LAX 23:39 · JFK 02:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.