Click here to Skip to main content
12,072,809 members (70,495 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Python2.7
I am using BeautifulSoup. I want to get the text "In Stock". Thanks.


<br>
<span style="font-weight:bold;">Stock Status</span>
:In Stock
<meta content="InStock" itemprop="availability">
<br>
Posted 11-Dec-12 13:43pm
MI12344260
Edited 11-Dec-12 13: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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

Now I get the required text.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160208.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100