Click here to Skip to main content
11,717,126 members (84,585 online)
Rate this: bad
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 12:43pm
Edited 11-Dec-12 12:44pm
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?
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
<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
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
0 Sergey Alexandrovich Kryukov 659
1 F-ES Sitecore 260
2 Maciej Los 185
3 OriginalGriff 175
4 Richard MacCutchan 140
0 Sergey Alexandrovich Kryukov 1,029
1 Maciej Los 464
2 Richard MacCutchan 430
3 CHill60 415
4 OriginalGriff 415

Advertise | Privacy | Mobile
Web03 | 2.8.150901.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