Pustaka Taratsa

Baca teks (EPUB): Python: Read Twitter

1 bagian

Teks ini diambil langsung dari berkas EPUB; tata letak dan gambar tidak disertakan. Untuk tampilan lengkap, silakan merujuk pada dokumen asli.

Daftar isi
  1. Python: Read Twitter
  2. Referensi

Python: Read Twitter

Sumber: https://onnocenter.or.id/wiki/index.php/Python:_Read_Twitter

import requests
from bs4 import BeautifulSoup
all_tweets = []
url = 'https://twitter.com/onnowpurbo'
data = requests.get(url)
html = BeautifulSoup(data.text, 'html.parser')
timeline = html.select('#timeline li.stream-item')
for tweet in timeline:
    tweet_id = tweet['data-item-id']
    tweet_text = tweet.select('p.tweet-text')[0].get_text()
    all_tweets.append({"id": tweet_id, "text": tweet_text})
    print(all_tweets) 

Referensi