Reputation: 228
I am trying to parse information from this web page: http://bigcharts.marketwatch.com/quickchart/quickchart.asp?symb=AAPL
The python code
list = [td.find('div') for td in soup1.find_all('td')]
returns 20 items. For example
print list[10]
returns
<div>100.60</div>
How do I simply have beautiful soup return "100.60". Alternatively, how could I strip the tags?
Upvotes: 1
Views: 124
Reputation: 9647
You can get the text
inside the tag using .text
or .string
method. In your case both will work. .text
will return a unicode
string and .string
will return a NavigableString
object.
print list[10].text
or,
print list[10].string
Check also the difference between .text
and .string
.
Also you can strip them using strip
method for string
objects. like,
list[10].text.strip()
Upvotes: 3