Created
July 22, 2012 01:04
-
-
Save idclark/3157830 to your computer and use it in GitHub Desktop.
Useful function to return text content free of HTML tags
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 | |
| import urllib2 | |
| # choose a url | |
| url = ' ' | |
| Soup = BeautifulSoup(urllib2.urlopen(url)) | |
| def get_tag_contents(tag_name): | |
| content_list = [] | |
| for tag in Soup.find_all(tag_name): | |
| contents = tag.contents | |
| content_list.append(contents) | |
| return content_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment