Python: Read Twitter: Difference between revisions

From OnnoCenterWiki
Jump to navigationJump to search
Onnowpurbo (talk | contribs)
Created page with " import requests from bs4 import BeautifulSoup if __name__ == ' __main__': all_tweets = [] url = 'https://twitter.com/onnowpurbo' data = requests.get(url)..."
 
Onnowpurbo (talk | contribs)
No edit summary
 
Line 2: Line 2:
  import requests
  import requests
  from bs4 import BeautifulSoup
  from bs4 import BeautifulSoup
if __name__ == ' __main__':
    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)


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)





Latest revision as of 10:00, 12 October 2019

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