Click here to Skip to main content
Rate this: bad
good
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 at 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 at 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 at 12-Dec-12 0:54am
   
try
<span style="font-weight:bold;" id="myspan">Stock Status</span>
and myspan.innerHTML could give result
MI12344 at 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
0 OriginalGriff 350
1 Jochen Arndt 150
2 PIEBALDconsult 110
3 Richard MacCutchan 105
4 Sergey Alexandrovich Kryukov 104
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2014
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