Ad
How Can I Split The Price To Get One Price
How can I split the output into two and get only the first or second part I tried this all_original_price = [o.text.split('>').split('₹') for o in all_original_price] but it did not work
from bs4 import BeautifulSoup as soup
import pandas as pd
import re
url = "https://www.amazon.in/s?k=smart+watch&page=1"
original_price =[]
amazon_data = urlopen(url)
amazon_html = amazon_data.read()
a_soup = soup(amazon_html,'html.parser')
all_original_price = a_soup.findAll('span',{'class':'a-price a-text-price'})
all_original_price = [o.text.split('>') for o in all_original_price]
for item in all_original_price:
original_price.append(item)
print(original_price)```
OUTPUT
[['₹4,999₹4,999'], ['₹6,400₹6,400'], ['₹4,999₹4,999'], ['₹5,999₹5,999'], ['₹4,999₹4,999'], ['₹5,999₹5,999'], ['₹3,999₹3,999'], ['₹6,990₹6,990'], ['₹7,999₹7,999'], ['₹1,599₹1,599'], ['₹5,999₹5,999'], ['₹4,999₹4,999'], ['₹5,999₹5,999'], ['₹4,999₹4,999'], ['₹4,999₹4,999'], ['₹9,999₹9,999'], ['₹6,999₹6,999']]
Ad
Answer
Try:
url = "https://www.amazon.in/s?k=smart+watch&page=1"
original_price =[]
amazon_data = urlopen(url)
amazon_html = amazon_data.read()
a_soup = soup(amazon_html,'html.parser')
all_original_price = a_soup.findAll('span',{'class':'a-price a-text-price'})
all_original_price = [o.find('span', {'class': 'a-offscreen'}).text.split('>') for o in all_original_price]
for item in all_original_price:
original_price.append(item[0])
Output:
>>> original_price
['₹4,999',
'₹6,400',
'₹4,999',
'₹5,999',
'₹4,999',
'₹5,999',
'₹3,999',
'₹6,990',
'₹7,999',
'₹1,599',
'₹5,999',
'₹4,999',
'₹5,999',
'₹4,999',
'₹4,999',
'₹9,999',
'₹6,990']
Ad
source: stackoverflow.com
Related Questions
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Django, code inside <script> tag doesn't work in a template
- → React - Django webpack config with dynamic 'output'
- → GAE Python app - Does URL matter for SEO?
- → Put a Rendered Django Template in Json along with some other items
- → session disappears when request is sent from fetch
- → Python Shopify API output formatted datetime string in django template
- → Can't turn off Javascript using Selenium
- → WebDriver click() vs JavaScript click()
- → Shopify app: adding a new shipping address via webhook
- → Shopify + Python library: how to create new shipping address
- → shopify python api: how do add new assets to published theme?
- → Access 'HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT' with Python Shopify Module
Ad