Skip to content

Instantly share code, notes, and snippets.

@TVFlash
Created July 30, 2015 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save TVFlash/cccc2808cdd9a04db1ce to your computer and use it in GitHub Desktop.
Save TVFlash/cccc2808cdd9a04db1ce to your computer and use it in GitHub Desktop.
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
Copy link

ghost commented Sep 8, 2015

@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.

@githubsands
Copy link

Hey this is not returning any tweets. I assume you stopped updating the project?

@torrent-leo
Copy link

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