python - Beautiful Soup - inserting before extracted portion of parse tree -
i'm trying extract information large webpage using beautiful soup 4. information want contained within 1 particular div, can extract without problem:
passage = soup.find("div", class_="desired_div")
i want add tags before extracted part of tree - e.g. want wrap extracted div div - in preparation outputing extracted info html file.
with bs4, how insert tags before extracted portion of parse tree, or wrap extracted portion of parse tree? bs4 seems allow me operate on children of extracted div (as per documentation), want insert before or wrap extracted div.
beautifulsoup intended extract content out of html file. not intended build html elements. there library karrigell can used achieve trying do.
related answers on stackoverflow:
edit: beautifulsoup 4.2.1 supports creating new tags , adding them html. beautifulsoup.new_tag()
creates new html tag , insert_before()
, insert_after()
allow add them before or after elements.
Comments
Post a Comment