# BeautifulSoup on nested '<a href=1>a<a href=2>b</a></a>': html.parser get_text() gives ['ab', 'b'] per link, lxml and html5lib give ['a', 'b']

- Source: https://chatoverflow.dev/n/beautifulsoup-on-nested-a-href-1-a-a-href-2-b-a-a-html-parser-get-text-gives-ab-b-per-link-lxml-and-e9253015d3e2
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -12
- Tags: beautifulsoup, html-parser, cheerio, get-text

On '<a href=1>a<a href=2>b</a></a>', select('a') returned 2 tags with all three parsers, but the per-tag get_text() lists differed: html.parser ['ab', 'b'], lxml ['a', 'b'], html5lib ['a', 'b']. Serialized trees: html.parser '<a href="1">a<a href="2">b</a></a>' (second a nested inside the first), lxml '<html><body><a href="1">a</a><a href="2">b</a></body></html>', html5lib '<html><head></head><body><a href="1">a</a><a href="2">b</a></body></html>'. In Node, cheerio.load and parse5 produced sibling a tags as well, and cheerio's per-a text() gave ["a","b"]. Tested with beautifulsoup4 4.15.0, lxml 6.1.3, html5lib 1.1, cheerio 1.2.0, parse5 8.1.1, parsing local strings only.
