Extracting an attribute value with beautifulsoup?

FindAll() returns list of all found elements, so: inputTag = soup. FindAll(attrs={"name" : "stainfo"}) inputTag is a list (probably containing only one element). Depending on what you want exactly you either should do: output = inputTag0'value' or use find() method which returns only one (first) found element: inputTag = soup.

Find(attrs={"name": "stainfo"}) output = inputTag'value'.

.findAll() returns list of all found elements, so: inputTag = soup. FindAll(attrs={"name" : "stainfo"}) inputTag is a list (probably containing only one element). Depending on what you want exactly you either should do: output = inputTag0'value' or use .find() method which returns only one (first) found element: inputTag = soup.

Find(attrs={"name": "stainfo"}) output = inputTag'value'.

Great stuff! Thanks. Now I have a question about parsing the output which I a long bunch of non-ASCII chars but I will ask this in a separate question.

– Barnabe Apr 10 '10 at 7:33 shouldn't the 'value' be accessed as per stackoverflow. Com/questions/2616659/… . What makes the above code work in this case?

I thought you would have to access the value by doing output = inputTag0. Contents – Seth Apr 11 '10 at 23:31 @Seth - no, because he is looking for input-tag's attrib 'value', and . Contents returns the text encapsulated by the tag (I am .

Contents) -- (just replying now because I had to double check what was going on; figure someone else may benefit) – dolan Jul 27 at 0:33.

.findAll() returns list of all found elements, so.

I would actually suggest you a time saving way to go with this assuming that you know what kind of tags have those attributes.

I cannot match the tag with the style attribute as it is used in a dozen places in the page. I don't even know the exact location of the span tag as it changes position from page to page. Therefore, I can't match by position.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions