Click here to Skip to main content
15,886,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using BeautifulSoup. I want to get the text "In Stock". Thanks.


XML
<br>
<span style="font-weight:bold;">Stock Status</span>
:In Stock
<meta content="InStock" itemprop="availability">
<br>
Posted
Updated 11-Dec-12 12:44pm
v2
Comments
Sergey Alexandrovich Kryukov 11-Dec-12 19:11pm    
Where is Python here? :-)
This is not even a question. What's the question and how it is related to this HTML code sample?
--SA
MI12344 11-Dec-12 19:54pm    
from BeautifulSoup import BeautifulSoup

soup = BeautifulSoup('<span style="font-weight:bold;">Stock Status</span>:In Stock<meta content="InStock" itemprop="availability">')
stock = soup.find(text='In Stock')
print stock

I tried with the above code but no result.
Hetal Jariwala 12-Dec-12 0:54am    
try
<span style="font-weight:bold;" id="myspan">Stock Status</span>
and myspan.innerHTML could give result
MI12344 13-Dec-12 1:11am    
style = soup.find('<span style="font-weight:bold;" id="myspan">Stock Status</span>')
stock = myspan.innerHTML
print stock

There is an error, I cannot even access the id that is created. What am I missing?

1 solution

style = soup.find('span', {'style':'font-weight:bold;'})
print style.next.next

Now I get the required text.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900