【问题标题】:Tweepy data is not appearing in JSON formatTweepy 数据未以 JSON 格式显示
【发布时间】:2015-06-26 02:56:33
【问题描述】:

我与 Tweepy 合作已经有一段时间了。我已经使用了他们的 api.search 以及流,一切正常,我能够很好地提取数据。

当我开始使用 api.lookup_users 时,我的结果没有以 json 格式显示,而是以其他格式显示,我无法使用以下格式提取数据:

tweet.text

或

tweet.username

这是我正在使用的用户查找代码:

user_id = api.lookup_users(user_ids=[2198765],include_entities=['True'])

print(user_id) 

这是我从 lookup_users 获得的部分数据:

[
User(profile_background_tile=False,
profile_location=None,
url='http: //t.co/7kRL5urm0d',
favourites_count=1262,
profile_text_color='000000',
notifications=False,
profile_background_image_url='http: //abs.twimg.com/images/themes/theme1/bg.png',
followers_count=10356,
lang='en',
is_translation_enabled=False,
is_translator=False,
contributors_enabled=False,
default_profile=False,
entities={
    'url': {
        'urls': [
            {

我确实通过 JSONValidator 运行了验证,但正如预期的那样,出现了一大堆错误。

Parse error on line 1:
[    User(profile_backgro
-----^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', ']'

** 编辑:

所以我环顾四周,发现 api.search 将在 <class 'tweepy.models.Status'> 中给出结果,而 api.lookup_users 在 <class 'tweepy.models.ResultSet'> 中。关于如何改变它的任何想法?

【问题讨论】:

    标签: python json twitter tweepy


    【解决方案1】:

    您将获得Model 实例的列表。通过查看代码,可以通过修改 self.parser = kwargs.pop('parser', api.parser) 模块中的 self.parser = kwargs.pop('parser', api.parser) 轻松覆盖此行为。您可以使用配置文件提供不同的parser。

    【讨论】:

    • 我认为它与解析有关,只是不知道如何修复它。我尝试编辑 lookup_users 函数本身,但没有奏效。所以您是说将self.parser = parser or ModelParser() 更改为您提供的内容?这不会改变所有功能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    相关资源
    最近更新 更多