Onna mage code eka. Puluwannam udaw karanna.
import requests
import json
from bs4 import BeautifulSoup
#Imitate the Mozilla browser.
user_agent = {'User-agent': 'Mozilla/5.0'}
laughs_coconut = '
https://www.laugfssuper.com/index.php/coconut.html'
glomark_coconut = '
https://glomark.lk/coconut/p/11624'
glomark_coca_colal_2l = "
https://glomark.lk/coca-cola-pet-2l/p/9613"
laughs_coca_colal_2l = "
https://www.laugfssuper.com/index.php/coca-cola-2l-pet.html"
laughs_bread = "
https://www.laugfssuper.com/index.php/crimson-bread.html"
glomark_bread = "
https://glomark.lk/top-crust-bread/p/13676"
def compare_prices(product_laughs,product_glomark):
glomark_result = requests.get(product_glomark)
src_glomark=glomark_result.content
soup_glomark = BeautifulSoup(src_glomark,'lxml')
script_glomark = soup_glomark.find_all('script')[6]
js_data_glomark=script_glomark.find(text=True,recursive=False)
data_glomark=json.loads(js_data_glomark)
price_glomark=float(data_glomark['offers'][0]['price'])
product_name_glomark=data_glomark['name']
result_laughs = requests.get(product_laughs)
src_laughs=result_laughs.content
soup_laughs = BeautifulSoup(src_laughs,'lxml')
scripttextprice_laughs= soup_laughs.find_all('span', class_='price')
product_name_laughs= soup_laughs.find('li',class_='product').getText()
arrprice=[]
for price in scripttextprice_laughs:
product_laughs=price.find(text=True,recursive=False)
arrprice.append(float(product_laughs[3:]))
price_laughs=arrprice[1]
# print('---------------------------------')
print('Laughs ', product_name_laughs, 'Rs.: ', str(price_laughs))
print('Glomark ', product_name_glomark, 'Rs.: ', str(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')
#print('---------------------------------')
compare_prices(laughs_coconut,glomark_coconut)
compare_prices(laughs_coca_colal_2l,glomark_coca_colal_2l)
compare_prices(laughs_bread,glomark_bread)
Oka waradie kiyala thamai enne.
Oyage code 1 puluwannam email 1k danna
[email protected]
import requests
import json
from bs4 import BeautifulSoup
#Imitate the Mozilla browser.
user_agent = {'User-agent': 'Mozilla/5.0'}
laughs_coconut = '
https://www.laugfssuper.com/index.php/coconut.html'
glomark_coconut = '
https://glomark.lk/coconut/p/11624'
glomark_coca_colal_2l = "
https://glomark.lk/coca-cola-pet-2l/p/9613"
laughs_coca_colal_2l = "
https://www.laugfssuper.com/index.php/coca-cola-2l-pet.html"
laughs_bread = "
https://www.laugfssuper.com/index.php/crimson-bread.html"
glomark_bread = "
https://glomark.lk/top-crust-bread/p/13676"
def compare_prices(product_laughs,product_glomark):
glomark_result = requests.get(product_glomark)
src_glomark=glomark_result.content
soup_glomark = BeautifulSoup(src_glomark,'lxml')
script_glomark = soup_glomark.find_all('script')[6]
js_data_glomark=script_glomark.find(text=True,recursive=False)
data_glomark=json.loads(js_data_glomark)
price_glomark=float(data_glomark['offers'][0]['price'])
product_name_glomark=data_glomark['name']
result_laughs = requests.get(product_laughs)
src_laughs=result_laughs.content
soup_laughs = BeautifulSoup(src_laughs,'lxml')
scripttextprice_laughs= soup_laughs.find_all('span', class_='price')
product_name_laughs= soup_laughs.find('li',class_='product').getText()
arrprice=[]
for price in scripttextprice_laughs:
product_laughs=price.find(text=True,recursive=False)
arrprice.append(float(product_laughs[3:]))
price_laughs=arrprice[1]
# print('---------------------------------')
print('Laughs ', product_name_laughs, 'Rs.: ', str(price_laughs))
print('Glomark ', product_name_glomark, 'Rs.: ', str(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')
#print('---------------------------------')
compare_prices(laughs_coconut,glomark_coconut)
compare_prices(laughs_coca_colal_2l,glomark_coca_colal_2l)
compare_prices(laughs_bread,glomark_bread)
Mage code 1 waradie kiyanawa.
Puluwan kenek correct code 1 email 1k dannako please
[email protected]
------
Post added on