python twitter爬网(scraping)JSON

2024-09-28 20:44:27 发布

您现在位置:Python中文网/ 问答频道 /正文

是的。(Pip install json,Pip install simplejson)

但是,会出现错误。你知道吗

  • 你知道吗simplejson.scanner.JSONDecodeError错误:起始于以下位置的未终止字符串: 第1行第65922列(字符65921)
  • 你知道吗tweepy.error.tweepy.error:无法分析JSON负载:从第1行第65922列(char 65921)开始的未终止字符串

我该怎么办?你知道吗

import tweepy
import time
import os
import json
import simplejson

search_term = 'word1'
search_term2= 'word2'
search_term3='word3'

lat = "xxxx"
lon = "xxxx"
radius = "xxxx"
location = "%s,%s,%s" % (lat, lon, radius)

API_key = "xxxx"
API_secret = "xxxx"
Access_token = "xxxx"
Access_token_secret = "xxxx"

auth = tweepy.OAuthHandler(API_key, API_secret)
auth.set_access_token(Access_token, Access_token_secret)

api = tweepy.API(auth)

c=tweepy.Cursor(api.search,
                q="{}+OR+{}".format(search_term, search_term2, search_term3),
                rpp=1000,
                geocode=location,
                include_entities=True)

data = {}
i = 1
for tweet in c.items():
    data['text'] = tweet.text
    print(i, ":", data)
    i += 1
    time.sleep(1)

wfile = open(os.getcwd()+"/workk2.txt", mode='w')   
data = {}   
i = 0       

for tweet in c.items():
    data['text'] = tweet.text   
    wfile.write(data['text']+'\n')  
    i += 1


wfile.close()

Tags: piptextimporttokenauthapisearchdata