Python Forum
How to get the first child of a beautifulSoup document ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get the first child of a beautifulSoup document ?
#1
Hi

I'am a little disappointed with beautifulSoup handling a tree.

>>> from bs4 import BeautifulSoup as btfs
>>> soup=btfs('', 'html5lib')
>>> soup
<html><head></head><body></body></html>
>>> for elem in soup.children:
...     print(elem)
... 
<html><head></head><body></body></html>
>>> 
I would expect, in the preceding example, soup to have as single child <html></html> rather than <html><head></head><body></body></html>.

Apparently, using another parser than html5lib does not make any difference.

So, how could I get <html></html> as a child of soup ?

Arbiel
using Ubuntu 18.04.4 LTS, Python 3.8
having substituted «https://www.lilo.org/fr/» to google, «https://protonmail.com/» to any other unsafe mail service and bépo to azerty (french keyboard layouts)
Reply


Messages In This Thread
How to get the first child of a beautifulSoup document ? - by arbiel - Jun-08-2020, 04:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020