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

在线求助,关于读取文本

  •  
  •   wdc63 · 2017-06-03 19:55:04 +08:00 · 2090 次点击
    这是一个创建于 2509 天前的主题,其中的信息可能已经有所发展或是发生改变。
    http://news.gtimg.cn/notice_more.php?q=sz300144&page=1
    如何能用比较简便的方法直接读取 finance_notice ={.....}这段话然后直接将其变成一个字典变量,并把其中的 ASCII 转换成文字。
    4 条回复    2017-06-03 21:52:21 +08:00
    XYxe
        1
    XYxe  
       2017-06-03 21:23:19 +08:00
    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  
       2017-06-03 21:27:41 +08:00   ❤️ 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
       2017-06-03 21:49:34 +08:00
    @ruoyu0088 朋友能不能用 P3 写一下
    wdc63
        4
    wdc63  
    OP
       2017-06-03 21:52:21 +08:00
    @ruoyu0088 谢谢,PY3 也可以安装 requests
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2035 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 16:15 · PVG 00:15 · LAX 09:15 · JFK 12:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.