Scraping data from Twitter without Twitter API

I am currently working on my master thesis. I want to run an sentiment analysis on the tweets directed at airlines that are about their sustainability initiatives. I wanted to use the API of X but Elon Musk thought it was necessary to ask for $100 per month to acces the data. Some guys from MIT found a way around this paywall.

  • https://medium.com/@vladkens/how-to-still-scrape-millions-of-tweets-in-2023-using-twscrape-97f5d3881434
  • https://github.com/vladkens/twscrape/tree/main

But the thing is that I am not familiar with the use if Python. Normally I use R for all my data analyzes, so I don’t know what I have to do. I need a CSV file with the tweet and the date so that I can run my analysis in R again.

I think I’ve altered the code so that I only get the tweets and the date but I can’t seem to get the output. The code stops after logging into the account that I’ve made for this to work. Before I actually got some output but I wasn’t able to export it to a CSV file unfortunately.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
import asyncio
from twscrape import API, gather
from twscrape.logger import set_log_level
async def main():
api = API() # or API("path-to.db") - default is `accounts.db`
# ADD ACCOUNTS (for CLI usage see BELOW)
await api.pool.add_account("pevers123", "2051Lb57", "[email protected]", "2051Lb57")
await api.pool.add_account("maxevers123", "2051Lb57", "[email protected]", "2051Lb57")
await api.pool.login_all()
# API USAGE
# search (latest tab)
await gather(api.search("easyjet eco-friendly environment", limit=20)) # list[Tweet]
# change search tab (product), can be: Top, Latest (default), Media
await gather(api.search("easyjet eco-friendly environment", limit=20, kv={"product": "Top"}))
# NOTE 1: gather is a helper function to receive all data as list, FOR can be used as well:
async for tweet in api.search("easyjet eco-friendly environment"):
print(tweet.user.username, tweet.rawContent, tweet.date) # tweet is `Tweet` object
if __name__ == "__main__":
asyncio.run(main())
</code>
<code> import asyncio from twscrape import API, gather from twscrape.logger import set_log_level async def main(): api = API() # or API("path-to.db") - default is `accounts.db` # ADD ACCOUNTS (for CLI usage see BELOW) await api.pool.add_account("pevers123", "2051Lb57", "[email protected]", "2051Lb57") await api.pool.add_account("maxevers123", "2051Lb57", "[email protected]", "2051Lb57") await api.pool.login_all() # API USAGE # search (latest tab) await gather(api.search("easyjet eco-friendly environment", limit=20)) # list[Tweet] # change search tab (product), can be: Top, Latest (default), Media await gather(api.search("easyjet eco-friendly environment", limit=20, kv={"product": "Top"})) # NOTE 1: gather is a helper function to receive all data as list, FOR can be used as well: async for tweet in api.search("easyjet eco-friendly environment"): print(tweet.user.username, tweet.rawContent, tweet.date) # tweet is `Tweet` object if __name__ == "__main__": asyncio.run(main()) </code>

import asyncio
from twscrape import API, gather
from twscrape.logger import set_log_level

async def main():
    api = API()  # or API("path-to.db") - default is `accounts.db`

    # ADD ACCOUNTS (for CLI usage see BELOW)
    await api.pool.add_account("pevers123", "2051Lb57", "[email protected]", "2051Lb57")
    await api.pool.add_account("maxevers123", "2051Lb57", "[email protected]", "2051Lb57")
    await api.pool.login_all()


    # API USAGE

    # search (latest tab)
    await gather(api.search("easyjet eco-friendly environment", limit=20))  # list[Tweet]
    # change search tab (product), can be: Top, Latest (default), Media
    await gather(api.search("easyjet eco-friendly environment", limit=20, kv={"product": "Top"}))


    # NOTE 1: gather is a helper function to receive all data as list, FOR can be used as well:
    async for tweet in api.search("easyjet eco-friendly environment"):
        print(tweet.user.username, tweet.rawContent, tweet.date)  # tweet is `Tweet` object


if __name__ == "__main__":
    asyncio.run(main())

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật