January 2014
Beginner
130 pages
2h 37m
English
Apart from the methods we saw before, Beautiful Soup has the following other methods for modifying the content:
insert_after() and insert_before() methods:As the name implies, these methods are used to insert a tag or string after or before another tag or string. The only parameter accepted by this method is the NavigavleString or Tag object.
For example, we can add another div tag with class=ecosystem to the ecological pyramid example using insert_after(). To use this, we need to first find the div tag with class=number within the first producer li ; this is shown as follows:
soup = BeautifulSoup(html_markup,"lxml") div_number = soup.find("div",class_="number") div_ecosystem = soup.new_tag("div") div_ecosystem['class'] ...Read now
Unlock full access