#  -*- coding: utf-8 -*-
#利用tweepy API爬取
import tweepy
import time
import json
from tweepy import OAuthHandler
import re
import os
import logging
logging.basicConfig()dict={}
L=[]
with open('label1.txt', 'r') as f:lines=f.read().splitlines()for i in lines:# print(i)line=re.split(":",i)L.append(line[1])dict[line[1]]=line[0]
# print("列表L为:",L)
# print("字典dict为:",dict)consumer_key =""
consumer_secret =""
access_token =""
access_token_secret =""auth = OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_token_secret)origin_result = []api = tweepy.API(auth,wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# api = tweepy.API(auth,proxy="http://mg.520ssr.ga:1080")
# tweet1=api.retweets("498430783699554305",200)
# re_tweet_ = api.retweets(id)
# print(tweet1[0])
# 获取某人的微博
# api.get_user('用户名').timeline()
for i in  range(40):origin_tweet = api.statuses_lookup(L[100:150])# print(len(origin_tweet))for t in origin_tweet:count=0# api.statuses_lookup([t.id_str])origin_result.append({'label':dict[t.id_str],'is_quote_status': t.is_quote_status,'user_geo_enabled':t.user.geo_enabled,'user_created_at':str(t.user.created_at),'verified':t.user.verified,'statuses_count': t.user.statuses_count,'location':t.user.location,'friends_count':t.user.friends_count,'followers_count':t.user.followers_count,'favorite_count':t.favorite_count,'retweet_count':t.retweet_count,'text': t.text,'user_name': t.user.screen_name,'tweet_created_at':str(t.created_at),'tweet_id':t.id_str,'user_id':t.user.id,'user_description':t.user.description})re_tweets = api.retweets(t.id_str,200)for tweet in re_tweets:# time.sleep(14)# print("休眠中")origin_result.append({'is_quote_status': tweet.is_quote_status,'user_geo_enabled': tweet.user.geo_enabled,'user_created_at': str(tweet.user.created_at),'verified': tweet.user.verified,'statuses_count': tweet.user.statuses_count,'location': tweet.user.location,'friends_count': tweet.user.friends_count,'followers_count': tweet.user.followers_count,'favorite_count': tweet.favorite_count,'retweet_count': tweet.retweet_count,'text': tweet.text,'user_name': tweet.user.screen_name,'tweet_created_at':str(tweet.created_at),'tweet_id':tweet.id_str,'user_id':tweet.user.id,'user_description':tweet.user.description})count=count+1with open(os.path.join("tweet15", t.id_str + ".json"), 'w+') as f:json.dump(origin_result, f, indent=4)print("Event :",len(origin_result))origin_result[:]=[]# print("速率限制,休眠中")# time.sleep(15*60)break
print("\n")
print("Total: ",len(os.listdir("tweet15")))# for tweet in tweet1:
#     # quote_tweet=api.statuses_lookup([tweet.id_str])
#     result.append({
#         'is_quote_status':tweet.is_quote_status,
#         'user_geo_enabled': tweet.user.geo_enabled,
#         'user_created_at': str(tweet.user.created_at),
#         'verified': tweet.user.verified,
#         'statuses_count': tweet.user.statuses_count,
#         'location': tweet.user.location,
#         'friends_count': tweet.user.friends_count,
#         'followers_count': tweet.user.followers_count,
#         'favorite_count': tweet.favorite_count,
#         'retweet_count': tweet.retweet_count,
#         'text': tweet.text,
#         'user_name': tweet.user.screen_name,
#         'tweet_created_at':str(tweet.created_at),
#         'tweet_id':tweet.id_str,
#         'user_id':tweet.user.id,
#         'user_description':tweet.user.description
#     })# print(t.coordinates)# print(tweet)# print(len(result))
# public_tweets = api.user_timeline(691809004356501505)
# public_tweets = api.statuses_lookup([691809004356501505])

tweepy 根据推特ID爬取推特数据相关推荐

  1. 爬取推糖网图片小案例

    前言: 好久没有更新博文了,因为工作的关系,一直没有更新博文,今天有空,就给大家带来一个爬图片的小案例.今天的目标网站就是堆糖网,关于爬取这个网站图片的案例,肯定大家都看到很多,基本都是通过搜索图片的 ...

  2. Python Scrapy 爬虫框架爬取推特信息及数据持久化!整理了我三天!

    最近要做一个国内外新冠疫情的热点信息的收集系统,所以,需要爬取推特上的一些数据,然后做数据分类及情绪分析.作为一名合格的程序员,我们要有「拿来主义精神」,借助别人的轮子来实现自己的项目,而不是从头搭建 ...

  3. python爬虫公众号_python爬虫_微信公众号推送信息爬取的实例

    问题描述 利用搜狗的微信搜索抓取指定公众号的最新一条推送,并保存相应的网页至本地. 注意点 搜狗微信获取的地址为临时链接,具有时效性. 公众号为动态网页(JavaScript渲染),使用request ...

  4. python 实时数据推送_python scrapy 爬取金十数据并自动推送到微信

    一.背景 因业务需要获取风险经济事件并采取应对措施,但因为种种原因又疏忽于每天去查看财经日历,于是通过爬取金十数据网站并自动推送到微信查看. 二.目标实现 image 三.环境与工具 1.pychar ...

  5. python微信爬取教程_python爬虫_微信公众号推送信息爬取的实例

    问题描述 利用搜狗的微信搜索抓取指定公众号的最新一条推送,并保存相应的网页至本地. 注意点 搜狗微信获取的地址为临时链接,具有时效性. 公众号为动态网页(JavaScript渲染),使用request ...

  6. python微信公众号推送_python爬虫_微信公众号推送信息爬取的实例

    问题描述 利用搜狗的微信搜索抓取指定公众号的最新一条推送,并保存相应的网页至本地. 注意点 搜狗微信获取的地址为临时链接,具有时效性. 公众号为动态网页(JavaScript渲染),使用request ...

  7. 爬取知乎回答点赞数_python3 爬虫 之只需要问题id爬取知乎问题全部回答

    先打个定心丸,本文所需要的技术点真的不难,我本来想要直接放代码的,但发现这次的不像之前写过的<Python3 + 教你只需要网易云音乐id + 爬取全部评论 + 生成词云图>那样需要解码, ...

  8. Python应用实战-Python爬取4000+股票数据,并用plotly绘制了树状热力图(treemap)

    目录: 1. 准备工作 2. 开始绘图 2.1. 简单的例子 2.2. px.treemap常用参数介绍 2.3. color_continuous_scale参数介绍 2.4. 大A股市树状热力图来 ...

  9. python 爬取链家数据_用python爬取链家网的二手房信息

    题外话:这几天用python做题,算是有头有尾地完成了.这两天会抽空把我的思路和方法,还有代码贴出来,供python的初学者参考.我python的实战经历不多,所以代码也是简单易懂的那种.当然过程中还 ...

最新文章

  1. rpm包管理功能全解
  2. SQL解析器的性能测试
  3. 蓝桥杯真题训练 2019.3题
  4. 如何开启Apache Rewrite功能
  5. 】oracle em配置常用命令
  6. 用matplotlib画sigmoid函数
  7. linux启动和grub修复
  8. GDPR 和个人信息保护的小知识
  9. 数字人民币的基础-共识与信任
  10. 利用GitHub Actions每天自动从Pixiv爬虫日推图片并存放到仓库
  11. c语言京东购物系统,仿京东商城: 自主使用微信小程序实现的网上商城案例(包括前端和后台),利用了微信小程序的云数据库...
  12. 专业动漫库好看的3d动漫推荐(3D动漫排行榜2022)
  13. 老版java奇缘幻境,老版奇缘幻境1
  14. 2023全网首发抖音标签检测程序源码+花800买的/最新版本
  15. F005-如是我观,知识产权 #F520
  16. 百度android模拟器下载地址,百度手机助手电脑版怎么下载 安卓模拟器电脑版下载地址...
  17. 显卡性价比排行榜2023 显卡天梯图2023年2月
  18. 华润杜邦物流信息化案例
  19. 复杂交通环境感知 | 基于深度学习的计算机视觉方法综述
  20. 5000词学英语——DAY4

热门文章

  1. win10如何显示我的电脑在桌面
  2. 多可系统如何增加新用户到工作组
  3. 【uniapp】将uni-app开发的安卓程序运行到雷电模拟器上进行调试
  4. 实时控制软件开发第二次作业总结
  5. 知识图谱与推荐系统(DKN)
  6. 软件测试工程师应届生工资,软件测试工程师薪水平均是什么水平?前景发展如何?...
  7. 计算CDS中密码子的数量
  8. 转载,常用RGB color
  9. python判断用户输入的两个单词是否字母相同,且出现的次数也一样
  10. 解决报错npm ERR request to https://registry.cnpmjs.org/wangeditor failed, reason: Hostname/