Created
July 30, 2015 13:25
-
-
Save TVFlash/cccc2808cdd9a04db1ce to your computer and use it in GitHub Desktop.
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, NavigableString | |
from urllib2 import urlopen | |
#Note: must be a public profile | |
print "Twitter username:" | |
user = raw_input() | |
endpoint = "https://twitter.com/%s" | |
f = urlopen(endpoint % user) | |
html = f.read() | |
f.close() | |
soup = BeautifulSoup(html, 'html.parser') | |
tweets = soup.find_all('strong', {'class': 'fullname js-action-profile-name show-popup-with-id'}) | |
for i in range(0,len(tweets)): | |
user = tweets[i].contents[0] | |
action_tag = soup('span', {'class': 'username js-action-profile-name'}) | |
show_name = action_tag[i].contents[1].contents[0] | |
twit_text = soup('p', {'class': 'js-tweet-text'}) | |
message = "" | |
for nib in twit_text[i]: | |
if isinstance(nib, NavigableString): | |
message += nib | |
else: | |
message += nib.text | |
print user, "@", show_name, message |
Hey this is not returning any tweets. I assume you stopped updating the project?
what's the content of raw_input() ,Please?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@TVFlash cheers, it works pretty well. However it only grabs the 20 latest tweets. I know that a lot of people would appreciate it if it grabbed all the tweets. Perhaps a duplication check and skip those that it has already grabbed? Assuming one outputs using *nix.