I need the string SKU: E02165 witch is somehow encoded as
SKU: E02165
by some means, here is the full div strait from the web site
<div class="sku">SKU: E02165 </div>
I have tried
soup = BeautifulSoup(data)
info = soup.find('div' , {'class':'sku'}).contents
as well all of the flowing
info = soup.findAll('div', { "class" : "sku"})
info = soup.find('div' , class='sku'}).contents
info = soup.find('div' , "class=" + 'sku'}).contents
info = soup.find('div' , {'class':'sku'}).text
info = soup.find('div' , {'class':'sku'}).contents
I have spent 2 hours strait on 2 lines of code if you can help me split the “sku:” from the number i think i could just use info = (info.split(‘sku: ‘)[1]) but if that dose nt work feel free to let me know.
thank you.
Try this:
get_text(strip=True)will get the text part of a document or tag with whitespace from the beginning and end stripped.encode('ascii', 'ignore')will ignore the unicodeu'\xa0'in the text and therefore allows thesplit()to return accurate result.Alternatively, you can also simply just do:
in which
replace(u'\xa0', u'')will replaceu'\xa0'with empty unicode string.