在线求助,关于读取文本

2017-06-03 19:55:04 +08:00
 wdc63
http://news.gtimg.cn/notice_more.php?q=sz300144&page=1
如何能用比较简便的方法直接读取 finance_notice ={.....}这段话然后直接将其变成一个字典变量,并把其中的 ASCII 转换成文字。
2108 次点击
所在节点    Python
4 条回复
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
2017-06-03 21:27:41 +08:00
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
2017-06-03 21:49:34 +08:00
@ruoyu0088 朋友能不能用 P3 写一下
wdc63
2017-06-03 21:52:21 +08:00
@ruoyu0088 谢谢,PY3 也可以安装 requests

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/365717

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX