Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help!!!!
#1
I need to write a program to acquire, extract and compare the price from these two suppliers, for a given product.

There are two online supermarkets which provide price of various products.

Example: The price of coconut from the two different suppliers can be found on the following web pages.

laughs_coconut = 'https://www.laugfssuper.com/index.php/coconut-105320.html'
glomark_coconut = 'https://glomark.lk/coconut/p/11624'
The function def compare_prices(product_laughs,product_glomark) will take in two similar products from two suppliers, and compare the prices to recommend which option is cheaper on a given instance of time.

Example expected output:

Laughs COCONUT - Item#mr-2058 Rs.: 89.0
Glomark Coconut Rs.: 86.0
Glomark is cheaper: 3.0
Here is the demo Code:
import requests
import json

import sys
sys.path.insert(0,'bs4.zip')
from bs4 import BeautifulSoup

#Imitate the Mozilla browser.
user_agent = {'User-agent': 'Mozilla/5.0'}


def compare_prices(product_laughs,product_glomark):
    #TODO: Aquire the web pages which contain product Price

    
    
    #TODO: LaughsSuper supermarket website provides the price in a span text.


    #TODO: Glomark supermarket website provides the data in jason format in an inline script.
    #You can use the json module to extract only the price
    
    
    #TODO: Parse the values as floats, and print them.
    
    print('Laughs  ',product_name_laughs,'Rs.: ' , price_laughs)
    print('Glomark ',product_name_glomark,'Rs.: ' , price_glomark)
    
    if(price_laughs>price_glomark):
        print('Glomark is cheaper Rs.:',price_laughs - price_glomark)
    elif(price_laughs<price_glomark):
        print('Laughs is cheaper Rs.:',price_glomark - price_laughs)    
    else:
        print('Price is the same')
Yoriz write Apr-24-2022, 11:09 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Use Code Tag.
This look like homework?
I can give example how to start,then you have to try stuff yourself to solve the task.
import requests
from bs4 import BeautifulSoup

url = 'https://www.laugfssuper.com/index.php/coconut-105320.html'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'lxml')
price = soup.find('div', class_="product-type-data")
Test.
>>> price
<div class="product-type-data"><div class="price-box"> <span class="regular-price" id="product-price-105320"> <span class="price">Rs.95.00</span> </span></div><p class="availability out-of-stock">Availability: <span>Out of stock</span></p></div>

>>> price.text.strip()
'Rs.95.00 Availability: Out of stock'
Reply
#3
Please help

import requests
import json

import sys
sys.path.insert(0,'bs4.zip')
from bs4 import BeautifulSoup

#Imitate the Mozilla browser.
user_agent = {'User-agent': 'Mozilla/5.0'}


def compare_prices(product_laughs,product_glomark):
    #TODO: Aquire the web pages which contain product Price

    
    
    #TODO: LaughsSuper supermarket website provides the price in a span text.


    #TODO: Glomark supermarket website provides the data in jason format in an inline script.
    #You can use the json module to extract only the price
    
    
    #TODO: Parse the values as floats, and print them.
    
    print('Laughs  ',product_name_laughs,'Rs.: ' , price_laughs)
    print('Glomark ',product_name_glomark,'Rs.: ' , price_glomark)
    
    if(price_laughs>price_glomark):
        print('Glomark is cheaper Rs.:',price_laughs - price_glomark)
    elif(price_laughs<price_glomark):
        print('Laughs is cheaper Rs.:',price_glomark - price_laughs)    
    else:
        print('Price is the same')
https://ibb.co/MnRbMQT
Gribouillis write Apr-24-2022, 08:46 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#4
I don't see the difference between the previous post and the original post. If you don't understand Snippsat's help above nor why you are getting an error, it is unlikely that you succeed in the given task. Try to understand what the example does.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020