UoM Online Course 3 - Python Programming එක ඉවර කරපු අය...

pasinduwi

Member
May 3, 2022
2
0
1
UoM Online Course 3 - Python Programming ඉවර කරපු අය...

course එක ඉවර කරපු කෙනෙක් ඉන්නවානම් කියන්න පුලුවන්ද Programming Assessment එකේ Code එක එන විදිහ Try කරලා බැලුවා .:sorry:🥲 කරගන්න බැරි නිසා help එකක් ඉල්ලලා බලන්න හිතුනේ..:rolleyes:

Programming Assessment එක​


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 :nerd:


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')
uththaraya hambunada mathathb ewannako
 

Denam98

Member
Jun 22, 2022
1
0
1
mamath godak danne na,mage code ekanam pass una,onenam dennam,ehema wadk nane igenaganne nathuwa,,prashna danna,danna deyak kiyala dennam,danne nathi deyak hoyala kiyannam
Glomark data tika gththa widiya poddak kiynwda
eke url eken ena response eka convert krgnna ba json object ekakata

inspect element gihilla oyata awashya element eke thiyena thana hoyaganna,eetapasse beautiful soup eken a place ekata gihin data eka ganna,eka variable ekaka save karaganna,a widihatama anith website ekatath karanna,
ekata ehema krta data enne na tag tika withri awe mata
------ Post added on Jun 22, 2022 at 6:35 AM
 

pasindu201

Well-known member
  • Dec 25, 2017
    1,738
    1,524
    113
    Glomark data tika gththa widiya poddak kiynwda
    eke url eken ena response eka convert krgnna ba json object ekakata


    ekata ehema krta data enne na tag tika withri awe mata
    ------ Post added on Jun 22, 2022 at 6:35 AM
    Glowmark eke data ganna wenne script ekaking,source code eka athule script tikak thiyenwa,eke 6 weni script eka thamai mama gaththe,eetapasse ekin json object ekak hadala eken filter karala gaththa

    htmlglow = requests.get(product_glomark,headers=user_agent).content

    glowSoup = BeautifulSoup(htmlglow, 'html.parser')


    #inline script contains the informaation,check source code
    findInlineScript= glowSoup.find_all('script')[6].text
    jsonObjectfromScript = json.loads(findInlineScript)



    price_glomark = float(jsonObjectfromScript["offers"][0]["price"])

    product_name_glomark = glowSoup.find_all('div',attrs={'class':'product-title'})

    for item in product_name_glomark:
    product_name_glomark = (item.find('h1').text)
     

    Rushdha

    Member
    Oct 13, 2022
    1
    0
    1
    mamath godak danne na,mage code ekanam pass una,onenam dennam,ehema wadk nane igenaganne nathuwa,,prashna danna,danna deyak kiyala dennam,danne nathi deyak hoyala kiyannam
    Can you send the code for assignment 7.1 in python 3?

    UoM Online Course 3 - Python Programming ඉවර කරපු අය...

    course එක ඉවර කරපු කෙනෙක් ඉන්නවානම් කියන්න පුලුවන්ද Programming Assessment එකේ Code එක එන විදිහ Try කරලා බැලුවා .:sorry:🥲 කරගන්න බැරි නිසා help එකක් ඉල්ලලා බලන්න හිතුනේ..:rolleyes:

    Programming Assessment එක​


    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 :nerd:


    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')
    Did you got the answer... Share it
    ------ Post added on Oct 14, 2022 at 1:11 PM
     

    Sam66

    Member
    Oct 25, 2022
    1
    0
    1
    mamath godak danne na,mage code ekanam pass una,onenam dennam,ehema wadk nane igenaganne nathuwa,,prashna danna,danna deyak kiyala dennam,danne nathi deyak hoyala kiyannam
    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 Oct 25, 2022 at 8:49 AM
     

    pasindu201

    Well-known member
  • Dec 25, 2017
    1,738
    1,524
    113
    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
    Python:
    from traceback import print_list
    import requests
    import json
    from bs4 import BeautifulSoup
    
    #Imitate the Mozilla browser.
    user_agent = {'User-agent': 'Mozilla/5.0'}
    
    
    def compare_prices(product_laughs,product_glomark):
    
        #Aquire the web pages which contain product Price
        htmlLaughs = requests.get(product_laughs).content
        htmlglow = requests.get(product_glomark,headers=user_agent).content
     
    
        soup = BeautifulSoup(htmlLaughs, 'html.parser')
    
      
        priceSpan = soup.find_all('span',attrs={'class':'price'})
        productnameElement = soup.find_all('div',attrs={'class':'product-name'})
    
        product_name_laughs=""
        for item in productnameElement:
            product_name_laughs = (item.find('h1').text)
            
    
        price_laughs=float(priceSpan[1].text[3:])
      
        product_name_glomark=""
        price_glomark=0.0;
    
        glowSoup = BeautifulSoup(htmlglow, 'html.parser')
    
        
        #inline script contains the informaation,check source code
        findInlineScript= glowSoup.find_all('script')[6].text
        jsonObjectfromScript = json.loads(findInlineScript)
    
    
      
        price_glomark = float(jsonObjectfromScript["offers"][0]["price"])
    
        product_name_glomark = glowSoup.find_all('div',attrs={'class':'product-title'})
    
        for item in product_name_glomark:
            product_name_glomark = (item.find('h1').text)
    
        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')
    
    
    if __name__ == "__main__":
        compare_prices("https://www.laugfssuper.com/index.php/coconut-105320.html","https://glomark.lk/coconut/p/11624")
     
    Mar 19, 2023
    1
    0
    1
    Assessment 01 - Server-side web programming karapu kenek nadda
    plz send me the answers for 4.7 in course 3
    can tou send the code of 4.7 in course 3

    Open Learning Platform - UoM

    Programming in Python - 2. Python Programming / 4. Programming for Computer Networks /4.7 Quiz



    Write a python program to retrieve all the products from the API Server and print the total number of products currently stored in the server.

    Hint: the json response will be of the following example format:



    {

    "message": "success",

    "data": [

    {

    "id": 85,

    "productName": "Araliya Basmathi Rice",

    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",

    "category": "Rice",

    "brand": "CIC",

    "expiredDate": "2023.05.04",

    "manufacturedDate": "2022.02.20",

    "batchNumber": 324567,

    "unitPrice": 1020,

    "quantity": 200,

    "createdDate": "2022.02.24"

    },

    {

    "id": 86,

    "productName": "Araliya Basmathi Rice",

    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",

    "category": "Rice",

    "brand": "CIC",

    "expiredDate": "2023.05.04",

    "manufacturedDate": "2022.02.20",

    "batchNumber": 324567,

    "unitPrice": 1020,

    "quantity": 200,

    "createdDate": "2022.02.24"



    },
    ------ Post added on Mar 19, 2023 at 4:08 PM

    Open Learning Platform - UoM
    Open Learning Platform - UoM

    Programming in Python - 2. Python Programming / 4. Programming for Computer Networks /4.7 Quiz



    Write a python program to retrieve all the products from the API Server and print the total number of products currently stored in the server.

    Hint: the json response will be of the following example format:



    {

    "message": "success",

    "data": [

    {

    "id": 85,

    "productName": "Araliya Basmathi Rice",

    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",

    "category": "Rice",

    "brand": "CIC",

    "expiredDate": "2023.05.04",

    "manufacturedDate": "2022.02.20",

    "batchNumber": 324567,

    "unitPrice": 1020,

    "quantity": 200,

    "createdDate": "2022.02.24"

    },

    {

    "id": 86,

    "productName": "Araliya Basmathi Rice",

    "description": "White Basmathi Rice imported from Pakistan. High-quality rice with extra fragrance. Organically grown.",

    "category": "Rice",

    "brand": "CIC",

    "expiredDate": "2023.05.04",

    "manufacturedDate": "2022.02.20",

    "batchNumber": 324567,

    "unitPrice": 1020,

    "quantity": 200,

    "createdDate": "2022.02.24"



    },
    ------ Post added on Mar 19, 2023 at 4:09 PM
     
    Jun 6, 2023
    2
    0
    1
    from traceback import print_list
    import requests
    import json

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

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



    def compare_prices(product_laughs,product_glomark):


    # laugfs product
    html_laugfs = requests.get(product_laughs).content
    soup_laugfs = BeautifulSoup(html_laugfs, 'html.parser')

    prod_laugfs = soup_laugfs.find('span',class_="regular-price")

    prodName = soup_laugfs.find('div',class_="product-name")
    product_name_laughs=prodName.get_text()

    prod_laugfs = prod_laugfs.get_text() # Will get text from html tags
    product_laugfs = prod_laugfs.strip() # Removing special characters like \n (newline)
    #print(product_name_laughs)
    prod_price_laugfs = product_laugfs[3:]
    price_laughs = float(prod_price_laugfs)
    #print(price_laughs)

    # Glomark product

    html_glomark = requests.get(product_glomark).content
    soup_glomark = BeautifulSoup(html_glomark, 'html.parser')

    prod_glomark = soup_glomark.find_all('script')[6].text
    prod_glomark = json.loads(prod_glomark)

    product_name_glomark = prod_glomark['description']
    offers_glomark = prod_glomark['offers'][0]
    price_glomark = float(offers_glomark['price'])
    #print(product_name_glomark)
    #print(price_glomark)


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

    me widihata wenas karanna one,hariyatama script eke number eka one,anika kalin oya manual function ekata call karala thibba ethakota deparak output eka print wenwa,ehema unama eyala dena test cases walata hariyanne na,mkada eyalage test case eke ekai oyage ekai dekak print wenwa
    ------ Post added on Apr 26, 2022 at 12:43 AM
    e mekath waradine eke not complete kiyalane watenne
     

    lahiru6628

    Member
    Feb 27, 2024
    2
    0
    1
    from traceback import print_list
    import requests
    import json

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

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



    def compare_prices(product_laughs,product_glomark):


    # laugfs product
    html_laugfs = requests.get(product_laughs).content
    soup_laugfs = BeautifulSoup(html_laugfs, 'html.parser')

    prod_laugfs = soup_laugfs.find('span',class_="regular-price")

    prodName = soup_laugfs.find('div',class_="product-name")
    product_name_laughs=prodName.get_text()

    prod_laugfs = prod_laugfs.get_text() # Will get text from html tags
    product_laugfs = prod_laugfs.strip() # Removing special characters like \n (newline)
    #print(product_name_laughs)
    prod_price_laugfs = product_laugfs[3:]
    price_laughs = float(prod_price_laugfs)
    #print(price_laughs)

    # Glomark product

    html_glomark = requests.get(product_glomark).content
    soup_glomark = BeautifulSoup(html_glomark, 'html.parser')

    prod_glomark = soup_glomark.find_all('script')[6].text
    prod_glomark = json.loads(prod_glomark)

    product_name_glomark = prod_glomark['description']
    offers_glomark = prod_glomark['offers'][0]
    price_glomark = float(offers_glomark['price'])
    #print(product_name_glomark)
    #print(price_glomark)


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

    me widihata wenas karanna one,hariyatama script eke number eka one,anika kalin oya manual function ekata call karala thibba ethakota deparak output eka print wenwa,ehema unama eyala dena test cases walata hariyanne na,mkada eyalage test case eke ekai oyage ekai dekak print wenwa
    ------ Post added on Apr 26, 2022 at 12:43 AM
    waradi kiyl enwne
     

    Don GasCan

    Well-known member
  • Nov 3, 2010
    43,224
    49,579
    113
    සේදවත්ත
    දැන් නම් ලොජික් එකයි අවුට් පුට් එකයි ලියකා chatgpt එකට කියලා කරගන්නවා බන් 😁
     

    lahiru6628

    Member
    Feb 27, 2024
    2
    0
    1
    waradi kiyala enawane kiyala hariyanne na machan,waradda mkadda ewanna one
    mchn enne bs4 install krl na kiyl wena awlk neweine
    err.PNG