Issue
**From the code given below I need to extract the value of 96 **
<div class="price">
<span id="product-promotion-price">Rs 96.00</span>
<br>
I tried the following code.But it didn't work
product_name_glomark = 'https://glomark.lk/coconut/p/11624'
html2 = requests.get(product_name_glomark).content
soup2 = BeautifulSoup(html2,'html.parser')
price_glomark = soup2.find("div",{"class":"price"}, {"id":"product-promotion-price"}).get_text()
product_name_glomark = soup2.find("div",{"class":"product-title"}).get_text()
Given below is the output
Solution
You can extract direct from script tag where listed. I return as float as future values may not be integers
import requests, re
product_name_glomark = 'https://glomark.lk/coconut/p/11624'
html2 = requests.get(product_name_glomark).text
price = float(re.search(r'"price": "(\d+?)"', html2).group(1))
print(price)
Answered By - QHarr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.