- 依赖
- 密码登录(服务器运行需要添加代理,一般的服务器IP都在twitter的黑名单)
from twikit import Client
username, password = '@d99','xxx'
proxy = 'http://www.xx.proxy:25'
proxies = {
'http://': proxy,
'https://': proxy
}
USERNAME = username
EMAIL = 'xx@gmail.com' #新IP登录需要邮箱接验证码
PASSWORD = password
# Initialize client
client = Client(
'en-US',
proxies=proxies
)
# Login to the service with provided user credentials
client.login(
auth_info_1=USERNAME ,
auth_info_2=EMAIL,
password=PASSWORD
)
- 通过搜索接口,搜索帖子
tweets = client.search_tweet('sora', 'Top')
for t in tweets:
# t.text
print(t.text)
每次都登陆肯定不行,得保存cooKies,通过cooKies登录
要是每次都以密码方式登录,应该很容易触发风控,有被封号的风险;
- 1、在首次密码登录后,将cooKies保存
- 2、定期刷新cooKies
- 保存cooKies
cookie_path = 'twitter_cookies.json'
client.save_cookies(cookie_path)
- 以cooKies的方式登录
client = Client(
'en-US',
proxies=proxies
)
client.load_cookies(cookie_path)
网友评论