python - How to extract values with BeautifulSoup with no class -
html code :
<td class="_480u"> <div class="clearfix"> <div> female </div> </div> </td>
i wanted value "female" output.
i tried bs.findall('div',{'class':'clearfix'})
; bs.findall('tag',{'class':'_480u'})
these classes on html code , output big list. wanted incorporate {td --> class = ".." , div --> class = ".."} in search, output female. how can this?
thanks
use stripped_strings
property:
>>> bs4 import beautifulsoup >>> >>> html = '''<td class="_480u"> ... <div class="clearfix"> ... <div> ... female ... </div> ... </div> ... </td>''' >>> soup = beautifulsoup(html) >>> print ' '.join(soup.find('div', {'class': 'clearfix'}).stripped_strings) female >>> print ' '.join(soup.find('td', {'class': '_480u'}).stripped_strings) female
or specify class empty string (or none
) , use string
property:
>>> soup.find('div', {'class': ''}).string u'\n female\n ' >>> soup.find('div', {'class': ''}).string.strip() u'female'
Comments
Post a Comment