1

For the link,

http://www.jabong.com/Adidas-Base-Mid-Dd-Blue-Round-Neck-T-Shirt-2733238.html

...I need to get the product fabric detail, "Polyster". But I get "Fabric" as output. Below is the part of code.

soup.find_all("span", {"class":"product-info-left"})[0].text

3 Answers 3

1

Find you node next_sibling.

soup.find_all("span", {"class":"product-info-left"})[0].next_sibling.text
Sign up to request clarification or add additional context in comments.

Comments

0

You can use .next or .next_sibling here :

>>> soup.find_all("span", {"class":"product-info-left"})[0].next.next.text
'Polyester'
>>> soup.find_all("span", {"class":"product-info-left"})[0].next_sibling.text
'Polyester'

Comments

0

The info you need is in the li tag which is under the ul tag, you should find the ul first, then you can get all the text in the li tag using stripped_strings

In [47]: r = requests.get('http://www.jabong.com/Adidas-Base-Mid-Dd-Blue-Round-Neck-T-Shirt-2733238.html')

In [48]: soup = BeautifulSoup(r.text, 'lxml')

In [49]: ul = soup.find('ul', class_="prod-main-wrapper")

In [50]: for li in ul.find_all('li'):
    ...:     print(list(li.stripped_strings))
    ...:     
['Fabric', 'Polyester']
['Sleeves', 'Half Sleeves']
['Neck', 'Round Neck']
['Fit', 'Regular']
['Color', 'Blue']
['Style', 'Solid']
['SKU', 'AD004MA61NGOINDFAS']
['Model Stats', 'This model has height 6\'0",Chest 38",Waist 34"and is Wearing Size M.']
['Authorization', 'Adidas authorized online sales partner.', 'View Certificate']

If you only want the first row, you can use find(), it will return the fists element in the find_all():

In [51]: text = ul.find('li').stripped_strings  
In [52]: print(list(text))
['Fabric', 'Polyester']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.