Extracting value in Beautifulsoup
Posted
by Seth
on Stack Overflow
See other posts from Stack Overflow
or by Seth
Published on 2010-04-11T10:05:06Z
Indexed on
2010/04/11
10:13 UTC
Read the original article
Hit count: 401
beautifulsoup
|python
I have the following code:
f = open(path, 'r')
html = f.read() # no parameters => reads to eof and returns string
soup = BeautifulSoup(html)
schoolname = soup.findAll(attrs={'id':'ctl00_ContentPlaceHolder1_SchoolProfileUserControl_SchoolHeaderLabel'})
print schoolname
which gives:
[<span id="ctl00_ContentPlaceHolder1_SchoolProfileUserControl_SchoolHeaderLabel">A B Paterson College, Arundel, QLD</span>]
when I try and access the value (i.e. 'A B Paterson College, Arundel, QLD) by using schoolname['value']
I get the following error:
print schoolname['value'] TypeError: list indices must be integers, not str
What am I doing wrong to get that value?
© Stack Overflow or respective owner