Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
Python Code help..
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="SL MULTIMEDIA TUTORIAL" data-source="post: 27628557" data-attributes="member: 575597"><p>mekata Code enne kohomada <img class="smilie smilie--emoji" loading="lazy" alt="👀" title="Eyes :eyes:" src="https://cdn.jsdelivr.net/joypixels/assets/6.6/png/unicode/64/1f440.png" data-shortname=":eyes:" /></p><p></p><p>There are two online supermarkets which provide price of various products.</p><p></p><p>You need to write a program to acquire, extract and compare the price from these two suppliers, for a given product.</p><p></p><p>Example: Price of a coconut from the two different suppliers can be found in the following webpages.</p><p></p><p>laughs_coconut = '<a href="https://www.laugfssuper.com/index.php/coconut-105320.html" target="_blank">https://www.laugfssuper.com/index.php/coconut-105320.html</a>' (Please check the update note at the end of the question)</p><p>glomark_coconut = '<a href="https://glomark.lk/coconut/p/11624" target="_blank">https://glomark.lk/coconut/p/11624</a>'</p><p></p><p>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.</p><p></p><p>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.</p><p>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.</p><p></p><p></p><p></p><p>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.</p><p>Example expected output</p><p></p><p>Laughs COCONUT - Item#mr-2058 Rs.: 89.0</p><p>Glomark Coconut Rs.: 86.0</p><p>Glomark is cheaper: 3.0</p><p></p><p>Here are some more test cases for you to test in your own computer.</p><p></p><p>laughs_tissues = '<a href="https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html" target="_blank">https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html</a>'</p><p>glomark_tissues = '<a href="https://glomark.lk/flora-facial-tissues-160s/p/10470" target="_blank">https://glomark.lk/flora-facial-tissues-160s/p/10470</a>'</p><p>compare_prices(laughs_tissues,glomark_tissues)</p><p></p><p>laughs_bread = <a href="https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html" target="_blank">https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html</a>'</p><p>glomark_bread = '<a href="https://glomark.lk/top-crust-bread/p/13676" target="_blank">https://glomark.lk/top-crust-bread/p/13676</a>'</p><p>compare_prices(laughs_bread,glomark_bread)</p><p></p><p>**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.:</p><p></p><p><a href="https://scrape-sm1.github.io/site1/COCONUT%20market1super.html" target="_blank">https://scrape-sm1.github.io/site1/COCONUT market1super.html</a></p><p><a href="https://scrape-sm1.github.io/site1/FLORA%20FACIAL%20TISSUES%202%20X%20160%20BOX%20-%20HOUSEHOLD%20-%20Categories%20market1super.com.html" target="_blank">https://scrape-sm1.github.io/site1/FLORA FACIAL TISSUES 2 X 160 BOX - HOUSEHOLD - Categories market1super.com.html</a></p><p><a href="https://scrape-sm1.github.io/site1/COCA%20COLA%202L%20(PET)%20-%20BEVERAGES%20-%20Categories%20market1ssuper.com.html" target="_blank">https://scrape-sm1.github.io/site1/COCA COLA 2L (PET) - BEVERAGES - Categories market1ssuper.com.html</a></p><p><a href="https://scrape-sm1.github.io/site1/Crimson%20Bread%20Sliced%20market1super.com.html" target="_blank">https://scrape-sm1.github.io/site1/Crimson Bread Sliced market1super.com.html</a></p><p></p><p>Stock Code eka <img src="/styles/default/xenforo/smilies/default/nerd.gif" class="smilie" loading="lazy" alt=":nerd:" title="Nerd :nerd:" data-shortname=":nerd:" /></p><p></p><p>[CODE=python]import requests</p><p>import json</p><p></p><p>import sys</p><p>sys.path.insert(0,'bs4.zip')</p><p>from bs4 import BeautifulSoup</p><p></p><p>#Imitate the Mozilla browser.</p><p>user_agent = {'User-agent': 'Mozilla/5.0'}</p><p></p><p></p><p>def compare_prices(product_laughs,product_glomark):</p><p> #TODO: Aquire the web pages which contain product Price</p><p></p><p> </p><p> </p><p> #TODO: LaughsSuper supermarket website provides the price in a span text.</p><p></p><p></p><p> #TODO: Glomark supermarket website provides the data in jason format in an inline script.</p><p> #You can use the json module to extract only the price</p><p> </p><p> </p><p> #TODO: Parse the values as floats, and print them.</p><p> </p><p> print('Laughs ',product_name_laughs,'Rs.: ' , price_laughs)</p><p> print('Glomark ',product_name_glomark,'Rs.: ' , price_glomark)</p><p> </p><p> if(price_laughs>price_glomark):</p><p> print('Glomark is cheaper Rs.:',price_laughs - price_glomark)</p><p> elif(price_laughs<price_glomark):</p><p> print('Laughs is cheaper Rs.:',price_glomark - price_laughs) </p><p> else:</p><p> print('Price is the same')[/CODE]</p></blockquote><p></p>
[QUOTE="SL MULTIMEDIA TUTORIAL, post: 27628557, member: 575597"] 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 = '[URL]https://www.laugfssuper.com/index.php/coconut-105320.html[/URL]' (Please check the update note at the end of the question) glomark_coconut = '[URL]https://glomark.lk/coconut/p/11624[/URL]' 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 = '[URL]https://www.laugfssuper.com/index.php/categories/household/flora-facial-tissues-2-x-160-box.html[/URL]' glomark_tissues = '[URL]https://glomark.lk/flora-facial-tissues-160s/p/10470[/URL]' compare_prices(laughs_tissues,glomark_tissues) laughs_bread = [URL]https://www.laugfssuper.com/index.php/crimson-bread-sliced-111452.html[/URL]' glomark_bread = '[URL]https://glomark.lk/top-crust-bread/p/13676[/URL]' 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.: [URL]https://scrape-sm1.github.io/site1/COCONUT%20market1super.html[/URL] [URL]https://scrape-sm1.github.io/site1/FLORA%20FACIAL%20TISSUES%202%20X%20160%20BOX%20-%20HOUSEHOLD%20-%20Categories%20market1super.com.html[/URL] [URL]https://scrape-sm1.github.io/site1/COCA%20COLA%202L%20(PET)%20-%20BEVERAGES%20-%20Categories%20market1ssuper.com.html[/URL] [URL]https://scrape-sm1.github.io/site1/Crimson%20Bread%20Sliced%20market1super.com.html[/URL] Stock Code eka :nerd: [CODE=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')[/CODE] [/QUOTE]
Insert quotes…
Verification
Awruddata maasa keeyada?
Post reply
Top
Bottom