Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Group_Two-Professor_Oak/PokemonTweet.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
29 lines (22 sloc)
937 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
def pokemon_tweet(howManyPosts): | |
page = "pokemon" | |
messages = set() | |
while True: | |
res = requests.get('https://twitter.com/'+ page) | |
bs = BeautifulSoup(res.content, 'lxml') | |
all_tweets = bs.find_all('div', {'class': 'tweet'}) | |
if all_tweets: | |
for tweet in all_tweets[:howManyPosts]: | |
context = tweet.find('div', {'class': 'context'}).text.replace("\n", " ").strip() | |
content = tweet.find('div', {'class': 'content'}) | |
message = content.find('div', {'class': 'js-tweet-text-container'}).text.replace("\n", " ").strip() | |
if message not in messages: | |
return message | |
#print() | |
messages.add(message) | |
else: | |
print("List is empty/account name not found.") | |
howManyPosts = 1 #This is pretty self-explanatory, it means how many posts you want to print | |
pokemon_tweet(howManyPosts) |