在网页上显示检索到的信息

我正在尝试构建一个程序来抓取一些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 ':'

steven35 回答:在网页上显示检索到的信息

只需将var mydata =添加到脚本中即可。 例如(tweets.js):

var mydata = {"id": 1193249691741216768,...}
本文链接:https://www.f2er.com/3130865.html

大家都在问