Skip to content
Advertisement

What is contents in beautifulsoup4 and the number string?

I’m trying a web scraping in bs4 and I don’t know what it is, Pls Someone explain it to me tnx

JavaScript

Advertisement

Answer

The contents attribute holds a list of child elements of the element. The .string attribute of an element contains the text content for the element.

Using this page as an example:

JavaScript

output for elem.contents

JavaScript

output for elem.contents[1].string

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement