извлечь данные из Twitter JSON в CSV - PullRequest
0 голосов
/ 14 декабря 2018

Я немного новичок в Python.Я уверен, что это обсуждалось в здесь здесь здесь и еще в некоторых других обсуждениях.К сожалению, все, что я пробовал с этими предложениями, завершилось с ошибкой: JSONDecodeError: Ожидаемое значение: строка 2, столбец 1 (символ 1).Мои данные из твиттера извлечены в json, выглядят так:

{"created_at":"Fri Dec 14 02:41:12 +0000 2018","id":1073407528057344000,"id_str":"1073407528057344000","text":"RT @Theswagboyq: How you let a dude with no car drive you crazy","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":4231015721,"id_str":"4231015721","name":"Hannah Grupposo","screen_name":"h_grupposo","location":null,"url":null,"description":null,"translator_type":"none","protected":false,"verified":false,"followers_count":133,"friends_count":144,"listed_count":0,"favourites_count":3332,"statuses_count":2467,"created_at":"Fri Nov 20 02:11:29 +0000 2015","utc_offset":null,"time_zone":null,"geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"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":false,"profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1026235074793152520\/o_hjJS1Z_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1026235074793152520\/o_hjJS1Z_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/4231015721\/1456272917","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweeted_status":{"created_at":"Thu Dec 13 03:27:17 +0000 2018","id":1073056736221761537,"id_str":"1073056736221761537","text":"How you let a dude with no car drive you crazy","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":556508728,"id_str":"556508728","name":"IG: @SwagBoyQ \ud83c\udfc1","screen_name":"Theswagboyq","location":"Houston, TX","url":"https:\/\/youtu.be\/Eghzju1qJtI","description":"United States of Texas","translator_type":"none","protected":false,"verified":false,"followers_count":15984,"friends_count":12633,"listed_count":126,"favourites_count":3999,"statuses_count":1351,"created_at":"Wed Apr 18 03:15:36 +0000 2012","utc_offset":null,"time_zone":null,"geo_enabled":true,"lang":"en","contributors_enabled":false,"is_translator":false,"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":true,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/1070433998017564675\/BTlyClmw_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/1070433998017564675\/BTlyClmw_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/556508728\/1537125916","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"quote_count":623,"reply_count":38,"retweet_count":5666,"favorite_count":20431,"entities":{"hashtags":[],"urls":[],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en"},"is_quote_status":false,"quote_count":0,"reply_count":0,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"Theswagboyq","name":"IG: @SwagBoyQ \ud83c\udfc1","id":556508728,"id_str":"556508728","indices":[3,15]}],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"en","timestamp_ms":"1544755272293"}

Я пробовал, например, что-то вроде этого:

with open('myFile.json', 'r') as f:
for line in f:
    tweet = json.loads(line) 
    print(json.dumps(tweet, indent=4))

это не удалось с ошибкой: JSONDecodeError: Ожидаемое значение: строка 2столбец 1 (символ 1).кто-нибудь может помочь в этом?Большое спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...