我正在尝试构建一个程序来抓取一些Twitter数据,然后以用户友好的格式在网页上显示它们(标题和内容)。到目前为止,我已经创建了刮板,并且已经将数据另存为JSON
文件。
for tweet in new_tweets:
outtweets=tweet._json
with open('Trumpstweets.json', 'a') as f:
print(outtweets)
f.write(json.dumps(outtweets))
这是我巨大的JSON文件的一部分。
{"id": 1193249691741216768, "created_at": "Sat Nov 09 19:31:10 +0000 2019", "contributors": null, "id_str": "1193249691741216768", "in_reply_to_screen_name": null, "geo": null, "entities": {"user_mentions": [], "symbols": [], "hashtags": [{"text": "MAGA", "indices":
我不确定如何向用户显示此数据。我对Python和JSON非常陌生。我正在尝试在网页上显示它。
<head>
<title>askyb - Load JSON File Locally by Javascript Without JQuery</title>
<script type="text/javascript" src="tweets.json"></script>
</head>
function load() {
var mydata = JSON.parse(tweets);
alert(mydata[0]);
alert(mydata[1]);
}
并且有错误:
在tweets.json:1 Uncaught SyntaxError: Unexpected token ':'
中
只需在脚本中添加var mydata =
。例如(tweets.js):
var mydata = {"id": 1193249691741216768, ...}