推荐学习书目
› 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
wdc63
V2EX  ›  Python

在线求助,关于读取文本

  •  
  •   wdc63 · Jun 3, 2017 · 3081 views
    This topic created in 3413 days ago, the information mentioned may be changed or developed.
    http://news.gtimg.cn/notice_more.php?q=sz300144&page=1
    如何能用比较简便的方法直接读取 finance_notice ={.....}这段话然后直接将其变成一个字典变量,并把其中的 ASCII 转换成文字。
    4 replies  •  2017-06-03 21:52:21 +08:00
    XYxe
        1
    XYxe  
       Jun 3, 2017
    s = requests.get("http://news.gtimg.cn/notice_more.php?q=sz300144&page=1")
    t = s.text[20:-2]
    t = t.replace("'", '"')
    json.loads(t)
    ruoyu0088
        2
    ruoyu0088  
       Jun 3, 2017   ❤️ 1
    import requests

    res = requests.get("http://news.gtimg.cn/notice_more.php?q=sz300144&page=1")

    text = res.content.decode()
    json_text = text[text.find("{"):text.rfind("}") + 1].replace("'", '"')

    import json

    json.loads(json_text)
    wdc63
        3
    wdc63  
    OP
       Jun 3, 2017
    @ruoyu0088 朋友能不能用 P3 写一下
    wdc63
        4
    wdc63  
    OP
       Jun 3, 2017
    @ruoyu0088 谢谢,PY3 也可以安装 requests
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   735 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 20:30 · PVG 04:30 · LAX 13:30 · JFK 16:30
    ♥ Do have faith in what you're doing.