See the documentation on how to append a tag:
soup = BeautifulSoup("<b></b>")
original_tag = soup.b
new_tag = soup.new_tag("a", href="http://www.example.com")
original_tag.append(new_tag)
original_tag
# <b><a href="http://www.example.com"></a></b>
new_tag.string = "Link text."
original_tag
# <b><a href="http://www.example.com">Link text.</a></b>
Related Contents:
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. Do you need to install a parser library?
- BeautifulSoup getting href [duplicate]
- Scraping: SSL: CERTIFICATE_VERIFY_FAILED error for http://en.wikipedia.org
- TypeError: a bytes-like object is required, not ‘str’ in python and CSV
- Beautiful Soup and extracting a div and its contents by ID
- ImportError: No Module Named bs4 (BeautifulSoup)
- retrieve links from web page using python and BeautifulSoup [closed]
- How to find children of nodes using BeautifulSoup
- Difference between BeautifulSoup and Scrapy crawler?
- can we use XPath with BeautifulSoup?
- How to find tags with only certain attributes – BeautifulSoup
- Get an attribute value based on the name attribute with BeautifulSoup
- Python/BeautifulSoup – how to remove all tags from an element?
- Test if an attribute is present in a tag in BeautifulSoup
- How to get HTML from a beautiful soup object
- python BeautifulSoup parsing table
- BeautifulSoup findAll() given multiple classes?
- BeautifulSoup – search by text inside a tag
- Install Beautiful Soup using pip [duplicate]
- Using BeautifulSoup to search HTML for string
- Converting html to text with Python
- Using Python and BeautifulSoup (saved webpage source codes into a local file)
- Using BeautifulSoup to find a HTML tag that contains certain text
- UnicodeEncodeError: ‘ascii’ codec can’t encode character at special name [duplicate]
- Python BeautifulSoup give multiple tags to findAll
- BeautifulSoup getText from between , not picking up subsequent paragraphs
- BeautifulSoup innerhtml?
- Extract the ‘src’ attribute from an ‘img’ tag using Beautiful Soup
- Using BeautifulSoup to extract text without tags
- Parsing HTML in python – lxml or BeautifulSoup? Which of these is better for what kinds of purposes?
- How can I get href links from HTML using Python?
- Beautifulsoup – nextSibling
- Rendered HTML to plain text using Python
- How to use CSS selectors to retrieve specific links lying in some class using BeautifulSoup?
- How can I parse a website using Selenium and Beautifulsoup in python? [closed]
- Deleting a div with a particular class using BeautifulSoup
- BeautifulSoup: extract text from anchor tag
- Python BeautifulSoup extract text between element
- BeatifulSoup4 get_text still has javascript
- Beautiful Soup findAll doesn’t find them all
- How to find tag with particular text with Beautiful Soup?
- Beautiful Soup find children for particular div
- Difference between .string and .text BeautifulSoup
- TypeError: object of type ‘Response’ has no len()
- Get all HTML tags with Beautiful Soup
- urllib.request.urlopen(url) with Authentication
- BeautifulSoup webscraping find_all( ): finding exact match
- Beautiful Soup cannot find a CSS class if the object has other classes, too
- Beautiful Soup if Class “Contains” or Regex?