Python, Beautifulsoup - Parsing Out A Tweet
I have a peice of HTML I took from the source of my Twitter timeline, shown here: http://pastebin.com/deefvbYw That's one Tweet I'll use for an example. I can't for the life of me
Solution 1:
soup = BeautifulSoup(twit)
name_tag = soup('strong', {'class': 'fullname js-action-profile-name show-popup-with-id'})
user = name_tag[0].contents[0]
action_tag = soup('span', {'class': 'username js-action-profile-name'})
at_sign = action_tag[0].contents[0].contents[0]
show_name = action_tag[0].contents[1].contents[0]
twit_text = soup('p', {'class': 'js-tweet-text'})
message = twit_text[0].contents[0]
url = twit_text[0].contents[1]['data-expanded-url']
print user, at_sign, show_name, message, url
The output:
Dmitri @ TheFPShow I do this all the time... http://www.youtube.com/watch?v=DF9WP87KNPk
Post a Comment for "Python, Beautifulsoup - Parsing Out A Tweet"