python Programming Glossary: tag.name
Editing XML as a dictionary in python? http://stackoverflow.com/questions/127606/editing-xml-as-a-dictionary-in-python '^level' for tag in tags_starting_with_level print tag.name # level1 # level2 Adding and inserting new nodes is pretty straightforward..
Sanitising user input using Python http://stackoverflow.com/questions/16861/sanitising-user-input-using-python comments comment.extract for tag in soup.findAll True if tag.name not in validTags tag.hidden True attrs tag.attrs tag.attrs for..
Remove a tag using BeautifulSoup but keep its contents http://stackoverflow.com/questions/1765848/remove-a-tag-using-beautifulsoup-but-keep-its-contents soup BeautifulSoup value for tag in soup.findAll True if tag.name not in VALID_TAGS tag.extract soup.renderContents Except I don't.. soup BeautifulSoup html for tag in soup.findAll True if tag.name in invalid_tags s for c in tag.contents if not isinstance..
BeautifulSoup: Get the contents of a specific table http://stackoverflow.com/questions/2935658/beautifulsoup-get-the-contents-of-a-specific-table url .read bs BeautifulSoup html table bs.find lambda tag tag.name 'table' and tag.has_key 'id' and tag 'id' Table1 rows table.findAll..
Extracting readable text from HTML using Python? http://stackoverflow.com/questions/3172343/extracting-readable-text-from-html-using-python recursively e.g. as a generator def nonScript tag return tag.name 'script' def getStrings root for s in root.childGenerator if..
Using only the DB part of Django http://stackoverflow.com/questions/579511/using-only-the-db-part-of-django name 'stackoverflow' if tag_query.count 0 tag tag_query 0 tag.name 'stackoverflowed' tag.save Nice simple and clean. Now without.. name 'stackoverflow' if tag_query.count 0 tag tag_query 0 tag.name 'stackoverflowed' tag.save except _rollback_on_exception finally..
Python HTML sanitizer / scrubber / filter http://stackoverflow.com/questions/699468/python-html-sanitizer-scrubber-filter soup BeautifulSoup value for tag in soup.findAll True if tag.name not in VALID_TAGS tag.hidden True return soup.renderContents..
Complex Beautiful Soup query http://stackoverflow.com/questions/706443/complex-beautiful-soup-query API . If you want a one liner soup.findAll lambda tag tag.name 'a' and tag.findParent 'strong' 'sans' and tag.findParent 'strong'..
|