Keshav Reddy
Keshav Reddy

Reputation: 51

Retrieve the text value from element in BeautifulSoup

I am trying to retrieve the price from the URl mentioned in the code.

import requests
from bs4 import BeautifulSoup

r = requests.get("http://www.forever21.com/IN/Product/Product.aspx?
 BR=LOVE21&Category=whatsnew_app&ProductID=2000054242&VariantID=")
soup = BeautifulSoup(r.content, 'html.parser')
#print(soup.prettify())
price = soup.find_all("font",{"class":"items_price"})
print(price)

#Output:
<font class="items_price">Rs.1,249</font>

I need just the price which is Rs.1,249 Can someone say what needs to be done? Thank you

Upvotes: 0

Views: 3435

Answers (2)

JRodDynamite
JRodDynamite

Reputation: 12613

Simply user .get_text()

>>> price = soup.find("font",{"class":"items_price"})
>>> print(price.get_text())
'Rs.1,249'

Upvotes: 0

chrxr
chrxr

Reputation: 1624

ResultSet is a list.

print (price[0].get_text())

Upvotes: 4

Related Questions