Skip to content
Advertisement

Extracting an attribute value with beautifulsoup

I am trying to extract the content of a single “value” attribute in a specific “input” tag on a webpage. I use the following code:

JavaScript

I get TypeError: list indices must be integers, not str

Even though, from the Beautifulsoup documentation, I understand that strings should not be a problem here… but I am no specialist, and I may have misunderstood.

Any suggestion is greatly appreciated!

Advertisement

Answer

.find_all() returns list of all found elements, so:

JavaScript

input_tag is a list (probably containing only one element). Depending on what you want exactly you either should do:

JavaScript

or use .find() method which returns only one (first) found element:

JavaScript
Advertisement