Click here to Skip to main content
11,930,788 members (56,098 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.

<span style="font-weight:bold;">Stock Status</span>
:In Stock
<meta content="InStock" itemprop="availability">
Posted 11-Dec-12 13:43pm
Edited 11-Dec-12 13:44pm
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?
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
<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
Please Sign up or sign in to vote.

Solution 1

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

Now I get the required text.

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
Web04 | 2.8.151126.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2015
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