Chapter 5. Modifying Content Using Beautiful Soup
Beautiful Soup can be used effectively to search or navigate within an HTML/XML document. Apart from this, we can also use Beautiful Soup to change the content of an HTML/XML document. Modification of the content means the addition or deletion of a new tag, changing the tag name, altering tag attribute values, changing text content, and so on. This is useful in situations where we need to parse the HTML/XML document, change its structure, and write it back as an HTML/XML document with the modification.
Consider a case where we have an HTML document with a <table>
tag holding around 1,000 or more rows (the <tr>
tag ) with an existing set of two columns (the <td>
tag ) per row. We want to add a new set of the two <td>
tags to each row. It would be highly inappropriate to manually add these <td>
tags for each of the <tr>
tags. In this case, we can use Beautiful Soup to search or/and navigate through...