mekata Code enne kohomada 
There are two online supermarkets which provide price of various products.
You need to write a program to acquire, extract and compare the price from these two suppliers, for a given product.
Example: Price of a coconut from the two different suppliers can be found in the following webpages.
laughs_coconut = 'https://www.laugfssuper.com/index.php/coconut-105320.html' (Please check the update note at the end of the question)
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 you which option is cheaper on a given instance of time.
1. Visit the links in your web browser, and use the Inspect elements / View page source tools of the browser to understand the structure of the web pages given above.
2. Complete the compare_prices function which is pre-loaded in the answer box to acquire and extract the price values from two web pages.
When you submit your answer to be checked, be patient for a while (up to 20 seconds) until its been checked with multiple test cases.
Example expected output
Laughs COCONUT - Item#mr-2058 Rs.: 89.0
Glomark Coconut Rs.: 86.0
Glomark is cheaper: 3.0
Here are some more test cases for you to test in your own computer.
laughs_tissues = 'https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html'
glomark_tissues = 'https://glomark.lk/flora-facial-tissues-160s/p/10470'
compare_prices(laughs_tissues,glomark_tissues)
laughs_bread = https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html'
glomark_bread = 'https://glomark.lk/top-crust-bread/p/13676'
compare_prices(laughs_bread,glomark_bread)
**Update:Laugfs website seems to be slow and changing quite frequently. So a backup of the required web pages are available in the following links. Your answers will be validated against these pages.:
https://scrape-sm1.github.io/site1/COCONUT market1super.html
https://scrape-sm1.github.io/site1/... HOUSEHOLD - Categories market1super.com.html
https://scrape-sm1.github.io/site1/...BEVERAGES - Categories market1ssuper.com.html
https://scrape-sm1.github.io/site1/Crimson Bread Sliced market1super.com.html
Stock Code eka
There are two online supermarkets which provide price of various products.
You need to write a program to acquire, extract and compare the price from these two suppliers, for a given product.
Example: Price of a coconut from the two different suppliers can be found in the following webpages.
laughs_coconut = 'https://www.laugfssuper.com/index.php/coconut-105320.html' (Please check the update note at the end of the question)
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 you which option is cheaper on a given instance of time.
1. Visit the links in your web browser, and use the Inspect elements / View page source tools of the browser to understand the structure of the web pages given above.
2. Complete the compare_prices function which is pre-loaded in the answer box to acquire and extract the price values from two web pages.
When you submit your answer to be checked, be patient for a while (up to 20 seconds) until its been checked with multiple test cases.
Example expected output
Laughs COCONUT - Item#mr-2058 Rs.: 89.0
Glomark Coconut Rs.: 86.0
Glomark is cheaper: 3.0
Here are some more test cases for you to test in your own computer.
laughs_tissues = 'https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html'
glomark_tissues = 'https://glomark.lk/flora-facial-tissues-160s/p/10470'
compare_prices(laughs_tissues,glomark_tissues)
laughs_bread = https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html'
glomark_bread = 'https://glomark.lk/top-crust-bread/p/13676'
compare_prices(laughs_bread,glomark_bread)
**Update:Laugfs website seems to be slow and changing quite frequently. So a backup of the required web pages are available in the following links. Your answers will be validated against these pages.:
https://scrape-sm1.github.io/site1/COCONUT market1super.html
https://scrape-sm1.github.io/site1/... HOUSEHOLD - Categories market1super.com.html
https://scrape-sm1.github.io/site1/...BEVERAGES - Categories market1ssuper.com.html
https://scrape-sm1.github.io/site1/Crimson Bread Sliced market1super.com.html
Stock Code eka

Python:
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')