パイソンによって【439】ツイート処理

1. JSON形式のテキストファイルの転送

  ツイートのテキストtxtファイルを読んで、JSON形式に変換し、プリントアウトすることができ、それはまた、詳細情報を抽出することができます

コード:

インポートJSON 
インポートOSの

フォルダパス= R "D:\ Twitterのデータ\データ\テスト" 
ファイル= os.listdir(フォルダパス)
os.chdir(フォルダパス)

#最初のTXTファイル取得
[0] tweets_data_path =ファイル

位ストアJSON形式のファイルこの配列
tweets_data = [] 
tweets_file =オープン(tweets_data_path、 "R")
tweets_fileの行のための:
    :試みる
        ツイート= json.loads(ライン)
        tweets_data.append(つぶやき)
    を除く:
        続ける
インデント付き#印刷JSON形式のファイル
を印刷する(JSON .dumps(tweets_data [0]、インデント= 4))

出力:

{ 
    "のcreated_at": "火6月25日午後08時44分34秒0000 2019"、
    "ID":1143621025550049280、
    "id_str": "1143621025550049280"、
    "テキスト":「オーストラリアは一晩POMSを破っ\ ud83d \ ude01 \ ud83c \ udfcf \ ud83c \ udde6 \ ud83c \ uddfa \ ud83c \ udff4 \ udb40 \ udc67 \ udb40 \ udc62 \ udb40 \ udc65 \ udb40 \ udc6e \ udb40 \ udc67 \ udb40 \ udc7f #AUSvENG #CmonAussie#CWC19" 、
    "ソース": " <a iPhone </a>のhref=\"http://twitter.com/download/iphone\" rel=\"nofollow\">ツイッター" 
    "切り捨て":偽、
    "in_reply_to_status_id":ヌル、
    " in_reply_to_status_id_str ":ヌル、
    "in_reply_to_user_id":ヌル、
    "in_reply_to_user_id_str ":ヌル、 
    "in_reply_to_screen_name":ヌル、 
    "ユーザー":{
        "ID":252426781、
        "id_str": "252426781"、
        "名": "ウィリーAitch"、
        "SCREEN_NAME": "WillyAitch"、
        "場所": "メルボルン、ビクトリア"、
        "URL":ヌル、
        2月に「2017年9月: "説明" 2018、最大5ヶ月、これまでだった。リッチモンド\ ud83d \ udc2f \ ud83d \ udc2f \ ud83d \ udc2fwon 2017 AFLプレミアシップ!フィラデルフィア・イーグルス\ ud83e \ udd85 \ ud83e \ udd85 \ ud83e \ udd85第52回スーパーボウルを獲得した」、
        "translator_type" : "なし"、
        "保護":偽、
        "検証":偽、
        "followers_count":417、
        "friends_count":1061、
        "listed_count":15、 
        "はcreated_at": "火2月15日午前4時55分59秒0000 2011"、 
        "favourites_count":18852、
        "statuses_count":17796、profile_sidebar_border_color ": "C0DEED"、 
        "profile_sidebar_fill_color": "DDEEF6"、
        "utc_offset":ヌル、
        "TIME_ZONE":ヌル、
        "geo_enabled":真、
        "LANG":ヌル、
        "contributors_enabled":偽、
        "is_translator":偽、
        "profile_background_color": "C0DEED"、
        "profile_background_image_url":「HTTP ://abs.twimg.com/images/themes/theme1/bg.png」、
        "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png"、
        "profile_background_tile":偽
        "profile_link_color": "1DA1F2"、
        "profile_sidebar_border_color": "C0DEED"、 
        "profile_use_background_image":真、
        "profile_text_color": "333333"、
        "profile_image_url": "http://pbs.twimg.com/profile_images/1112669591342211072/rnbV0dCK_normal.jpg"、
        "profile_image_url_https":「https://pbs.twimg.com/profile_images/1112669591342211072 /rnbV0dCK_normal.jpg」、
        "profile_banner_url": "https://pbs.twimg.com/profile_banners/252426781/1522377977"、
        "DEFAULT_PROFILE":真、
        "default_profile_image":偽、
        "次":ヌル、
        "follow_request_sent":ヌル、
        "通知":NULL 
    }、
    "GEO":ヌル、
    "座標":ヌル、
    "場所":{ 
        "ID": "01864a8a64df9dc4"、 
        "URL": "https://api.twitter.com/1.1/geo/id/01864a8a64df9dc4.json」、 
        "place_type": "都市"、 
        "名": "メルボルン"、
        "FULL_NAME": "メルボルン、ビクトリア"、
        "COUNTRY_CODE":「AU 」、
        "国": "オーストラリア"、
        "BOUNDING_BOX":{ 
            "タイプ": "多角形"、
            "座標":[ 
                [ 
                    [ 
                        144.593742、
                        -38.433859 
                    ]、
                    [ 
                        144.593742、
                        -37。511274 
                    ]、
                    [ 
                        145.512529、 
                        -37。511274 
                    ]、
                    [
                        145.512529、
                        -38.433859 
                    ] 
                ] 
            ] 
        }、
        "属性":{} 
    }、
    "貢献":ヌル、
    "is_quote_status":偽、
    "quote_count":0、
    "reply_count":0、
    "retweet_count":0、
    "favorite_count" :0、
    "エンティティ" { 
        "ハッシュタグ":[ 
            { 
                "テキスト": "AUSvENG"、
                "インデックス" [ 
                    46、
                    54 
            { 
                ]
            }、
                "テキスト": "CmonAussie"、
                "インデックス" [ 
                    55、
                    66 
                ] 
            }、
            { 
                "テキスト": "CWC19"、
                "インデックス" [ 
                    67、
                    73 
                ] 
            } 
        ]、
        "URLを":[]、
        " user_mentions ":[]、
        "記号":[] 
    }、
    "お気に入りに追加":偽、
    "リツイート":偽、
    "filter_level": ""低
    、 "LANG": "EN"、
    "timestamp_ms": "1561495474599"
}

 

おすすめ

転載: www.cnblogs.com/alex-bn-lee/p/11576335.html