-
-
Save jeffatennis/c5cef0dc1c2d28a5aa01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment