{"id":863,"date":"2021-01-28T00:16:34","date_gmt":"2021-01-27T16:16:34","guid":{"rendered":"https:\/\/byy3.com\/?p=863"},"modified":"2021-01-28T02:34:20","modified_gmt":"2021-01-27T18:34:20","slug":"product-analysis-using-web-scraping-technique-in-python-open-code","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=863","title":{"rendered":"Product Analysis using Web Scraping Technique in Python open code"},"content":{"rendered":"<article>\n<div>\n<section class=\"cq gy gz cl ha\">\n<div class=\"n p\">\n<div class=\"ai aj ak al am ga ao v\">\n<p id=\"c09a\" class=\"ht hu hc hv b hw he hx hy hh hz ia ib ic id ie if ig ih ii ip ik cq et\" data-selectable-paragraph=\"\">Web Scraping is one of the Data Scraping technique in which data is extracted from the websites for analysis.In this project we will learn the how to analyze the product in an online shop like flipkart, for example we will analyze various brands of Mobile Tablets sold in the flipkart web site and suggest the medium range product in price range.<\/p>\n<p id=\"b856\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">Using the web scraping techniques we will be able to get the details prices,specifications, reviews,highlights and ratings for any product in the website.<\/p>\n<p id=\"3d89\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">We will be using the python modules urlopen(from urllib library) and BeautifulSoup(from bs4 library).<\/p>\n<blockquote class=\"im in qe\">\n<p id=\"1277\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">import bs4<br \/>\nimport pandas as pd<br \/>\nimport numpy as np<br \/>\nimport seaborn as sns<br \/>\nimport matplotlib.pyplot as plt<br \/>\nfrom urllib.request import urlopen as uReq<br \/>\nfrom bs4 import BeautifulSoup as soup<\/p>\n<\/blockquote>\n<p id=\"3bdf\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">Fi<span id=\"rmm\">r<\/span>st we need to read the contents of the web page which displays the search results of the product we are going to analyse ,the tablet and parse the html content using the BeautifulSoup module.<\/p>\n<blockquote class=\"im in qe\">\n<p id=\"f6ff\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">myurl = \u201c<a class=\"cw qf\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/www.flipkart.com\/tablets\/pr?sid=tyy,hry&amp;marketplace=FLIPKART\" target=\"_blank\" rel=\"noopener nofollow\" rel=\"nofollow\" >https:\/\/www.flipkart.com\/tablets\/pr?sid=tyy,hry&amp;marketplace=FLIPKART<\/a>\"<br \/>\nuclient = uReq(myurl)<br \/>\npage_html = uclient.read()<br \/>\nuclient.close()<\/p>\n<p id=\"b48c\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">psoup = soup(page_html, \u201chtml.parser\u201d)<\/p>\n<\/blockquote>\n<p id=\"e932\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">Below is the screen short of the web page we are going to get the data for analysis,right click on the page and do inspect, it will show the HTML document tags for each element in the page.<\/p>\n<figure class=\"gb qh qi qj qk kw gg gh paragraph-image\">\n<div class=\"ql qm ag qn v qo\" tabindex=\"0\" role=\"button\">\n<div class=\"gg gh qg\">\n<div class=\"lb y ag lc\">\n<div class=\"qp le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*OJj2aknImzTPLBjM1Nu5_A.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"1841\" height=\"938\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/2762\/1*OJj2aknImzTPLBjM1Nu5_A.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*OJj2aknImzTPLBjM1Nu5_A.png 276w, https:\/\/miro.medium.com\/max\/828\/1*OJj2aknImzTPLBjM1Nu5_A.png 552w, https:\/\/miro.medium.com\/max\/960\/1*OJj2aknImzTPLBjM1Nu5_A.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*OJj2aknImzTPLBjM1Nu5_A.png 700w\" width=\"1841\" height=\"938\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe1\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe1\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p id=\"6303\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">Right click on the Page index tab in the page select the inspect option and search for the elements listing and find the class name for that element and use it for getting the href of the link to the search result pages for all the product listed,as show in the picture below<\/p>\n<figure class=\"gb qh qi qj qk kw gg gh paragraph-image\">\n<div class=\"ql qm ag qn v qo\" tabindex=\"0\" role=\"button\">\n<div class=\"gg gh qq\">\n<div class=\"lb y ag lc\">\n<div class=\"qr le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*dA3jWvaukbMkdW4_yBVT5A.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"1849\" height=\"957\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe2\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe2\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/2774\/1*dA3jWvaukbMkdW4_yBVT5A.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*dA3jWvaukbMkdW4_yBVT5A.png 276w, https:\/\/miro.medium.com\/max\/828\/1*dA3jWvaukbMkdW4_yBVT5A.png 552w, https:\/\/miro.medium.com\/max\/960\/1*dA3jWvaukbMkdW4_yBVT5A.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*dA3jWvaukbMkdW4_yBVT5A.png 700w\" width=\"1849\" height=\"957\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe3\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe3\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p id=\"71ca\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">Now find all the page references and store it in a list,as detailed in the code below<\/p>\n<blockquote class=\"im in qe\">\n<p id=\"0fe0\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">page_urls = list()<br \/>\nfor containers in psoup.findAll(\u2018div\u2019,{\u2018class\u2019:\u2019_2MImiq\u2019}):<br \/>\na_list = containers.findAll(\u2018a\u2019,{\u2018class\u2019:\u2019ge-49M\u2019})<\/p>\n<p>#uncomment and use the below 2 lines to get all the search 10 pages<br \/>\n#for a in a_list:<br \/>\n# page_urls.append(\u2018<a class=\"cw qf\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/www.flipkart.com%27+\/\" target=\"_blank\" rel=\"noopener nofollow\" rel=\"nofollow\" >https:\/\/www.flipkart.com\u2019+<\/a>\u00a0a[\u2018href\u2019])<\/p>\n<p>#use the below 2 lines to get single search page<br \/>\na= a_list[0]<br \/>\npage_urls.append(\u2018<a class=\"cw qf\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/www.flipkart.com%27+\/\" target=\"_blank\" rel=\"noopener nofollow\" rel=\"nofollow\" >https:\/\/www.flipkart.com'+<\/a>\u00a0a[\u2018href\u2019])<\/p><\/blockquote>\n<p id=\"76ff\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">Once we get the page url link, we need to inspect each product listed in the page as below<\/p>\n<blockquote class=\"im in qe\">\n<p id=\"2a01\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">for url in page_urls:<br \/>\nprint(url)<br \/>\nuclient = uReq(url)<br \/>\npage_html = uclient.read()<br \/>\nuclient.close()<br \/>\npsoup = soup(page_html, \u201chtml.parser\u201d)<\/p>\n<p id=\"e4c5\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">prod_urls = list()<br \/>\nfor containers in psoup.findAll(\u2018div\u2019,{\u2018class\u2019:\u2019_13oc-S\u2019}):<br \/>\nfor a in containers:<br \/>\na_list = a.findAll(\u2018a\u2019,{\u2018class\u2019:\u2019_1fQZEK\u2019})<br \/>\n#print(a_list[\u2018href\u2019])<br \/>\n#prod_urls.append(\u2018<a class=\"cw qf\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/www.flipkart.com%27+\/\" target=\"_blank\" rel=\"noopener nofollow\" rel=\"nofollow\" >https:\/\/www.flipkart.com\u2019+<\/a>\u00a0a_list[\u2018href\u2019])<\/p>\n<p>for a in a_list:<br \/>\nprod_urls.append(\u2018<a class=\"cw qf\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/www.flipkart.com%27+\/\" target=\"_blank\" rel=\"noopener nofollow\" rel=\"nofollow\" >https:\/\/www.flipkart.com'+<\/a>\u00a0a[\u2018href\u2019])<\/p>\n<p>for p_url in prod_urls:<br \/>\nuclient = uReq(p_url)<br \/>\npage_html = uclient.read()<br \/>\nuclient.close()<br \/>\npsoup = soup(page_html, \u201chtml.parser\u201d)<\/p>\n<p>all_procuct_items = psoup.find(\u2018div\u2019, attrs={\u2018class\u2019 : \u2018_3k-BhJ\u2019})<br \/>\nall_procuct_items = all_procuct_items.findAll(\u2018tr\u2019, attrs={\u2018class\u2019 : \u2018_1s_Smc row\u2019})<\/p>\n<p>#container variable contains the html of product title which is stored in div tag and class is \u201c_1AtVbE col-12\u201312\u201d<br \/>\ncontainer= psoup.findAll(\u201cdiv\u201d,{\u201cclass\u201d:\u201d_1AtVbE col-12\u201312\"})<br \/>\nfor product_item in container:<br \/>\nproduct_dict = dict()<br \/>\nrating_dict= dict()<br \/>\nprice_dict = dict()<br \/>\nbrandname_dict = dict()<br \/>\nn = product_item.findAll(\u201cspan\u201d,{\u201cclass\u201d:\u201dB_NuCI\u201d})<br \/>\np = product_item.findAll(\u201cdiv\u201d,{\u201cclass\u201d:\u201d_30jeq3 _16Jk6d\u201d})<\/p>\n<p>r = product_item.findAll(\u201cdiv\u201d,{\u201cclass\u201d:\u201d_2d4LTz\u201d})<br \/>\nfor i in n:<br \/>\nproduct_dict[\u2018name\u2019] = i.text<br \/>\nstrtmp = i.text.split(\u201c \u201c)<br \/>\nbrandname_dict[\u2018brandname\u2019] = strtmp[0]<br \/>\nbrandnames_list.append(strtmp[0])<br \/>\nproducts_list.append(i.text)<br \/>\nfor j in p:<br \/>\njStr = j.text<br \/>\njStr = jStr.replace(\u201c\u20b9\u201d, \u201c\u201d)<br \/>\njStr = jStr.replace(\u201c,\u201d, \u201c\u201d)<br \/>\nprice_dict[\u2018price\u2019] = int( jStr)<br \/>\nprices_list.append(int( jStr))<br \/>\nfor k in r:<br \/>\n#print (i.text)<br \/>\nrating_dict[\u2018rating\u2019] = k.text<br \/>\nratings_list.append(k.text)<\/p><\/blockquote>\n<p id=\"c28a\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">We can now export data extracted for the details of the products to the csv file using the code below<\/p>\n<blockquote class=\"im in qe\">\n<p id=\"f013\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">df = pd.DataFrame({\u2018Brand\u2019:brandnames_list,\u2019Price\u2019:prices_list,\u2019Ratings\u2019:ratings_list,\u2019ProductName\u2019:products_list})<br \/>\ndf.to_csv (\u2018export_products_dataframe.csv\u2019)<\/p>\n<\/blockquote>\n<p id=\"398a\" class=\"ht hu hc hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">We can use the box plot ,cat plot and bar plot available in the seaborn module for visualizing the price range of the product as shown in the pictures below,using the code below<\/p>\n<blockquote class=\"im in qe\">\n<p id=\"ea31\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">df[\u2018Price\u2019] = df[\u2018Price\u2019].astype(np.float)<br \/>\nsns.boxplot(x=df[\u2018Price\u2019])<\/p>\n<p id=\"7036\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">sns.catplot(x = \u201cPrice\u201d, # x variable name<br \/>\ny = \u201cBrand\u201d, # y variable name<br \/>\nhue = \u201cRatings\u201d, # group variable name<br \/>\ndata = df, # dataframe to plot<br \/>\nkind = \u201cbar\u201d)<\/p>\n<p id=\"b884\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">df.groupby(\u2018Brand\u2019).plot(x=\u2019Brand\u2019, y=\u2019Price\u2019)<\/p>\n<p id=\"6a85\" class=\"ht hu io hv b hw pz he hx hy qa hh hz ia qb ib ic id qc ie if ig qd ih ii ik cq et\" data-selectable-paragraph=\"\">sns.barplot(x = \u2018Brand\u2019,<br \/>\ny = \u2018Price\u2019,<br \/>\ndata = df)<\/p>\n<\/blockquote>\n<figure class=\"gb qh qi qj qk kw gg gh paragraph-image\">\n<div class=\"ql qm ag qn v qo\" tabindex=\"0\" role=\"button\">\n<div class=\"gg gh qs\">\n<div class=\"lb y ag lc\">\n<div class=\"qt le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*O_XRw3EslY106UsTrRLDqQ.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"875\" height=\"648\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe4\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe4\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/1313\/1*O_XRw3EslY106UsTrRLDqQ.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*O_XRw3EslY106UsTrRLDqQ.png 276w, https:\/\/miro.medium.com\/max\/828\/1*O_XRw3EslY106UsTrRLDqQ.png 552w, https:\/\/miro.medium.com\/max\/960\/1*O_XRw3EslY106UsTrRLDqQ.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*O_XRw3EslY106UsTrRLDqQ.png 700w\" width=\"875\" height=\"648\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe5\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe5\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div><figcaption class=\"qu qv op gg gh qw qx au b av aw ax\" data-selectable-paragraph=\"\">Product listing based on ratings and prices<\/figcaption><\/figure>\n<figure class=\"gb qh qi qj qk kw gg gh paragraph-image\">\n<div class=\"ql qm ag qn v qo\" tabindex=\"0\" role=\"button\">\n<div class=\"gg gh qy\">\n<div class=\"lb y ag lc\">\n<div class=\"qz le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*1IZrNoXleU_OKxF3ojXp5A.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"910\" height=\"555\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe6\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe6\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/1365\/1*1IZrNoXleU_OKxF3ojXp5A.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*1IZrNoXleU_OKxF3ojXp5A.png 276w, https:\/\/miro.medium.com\/max\/828\/1*1IZrNoXleU_OKxF3ojXp5A.png 552w, https:\/\/miro.medium.com\/max\/960\/1*1IZrNoXleU_OKxF3ojXp5A.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*1IZrNoXleU_OKxF3ojXp5A.png 700w\" width=\"910\" height=\"555\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe7\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe7\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div><figcaption class=\"qu qv op gg gh qw qx au b av aw ax\" data-selectable-paragraph=\"\">Price Range chart<\/figcaption><\/figure>\n<figure class=\"gb qh qi qj qk kw gg gh paragraph-image\">\n<div class=\"ql qm ag qn v qo\" tabindex=\"0\" role=\"button\">\n<div class=\"gg gh ra\">\n<div class=\"lb y ag lc\">\n<div class=\"rb le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*6agxCn-cCNmmgzO7NkzyEA.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"791\" height=\"485\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe8\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe8\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/1187\/1*6agxCn-cCNmmgzO7NkzyEA.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*6agxCn-cCNmmgzO7NkzyEA.png 276w, https:\/\/miro.medium.com\/max\/828\/1*6agxCn-cCNmmgzO7NkzyEA.png 552w, https:\/\/miro.medium.com\/max\/960\/1*6agxCn-cCNmmgzO7NkzyEA.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*6agxCn-cCNmmgzO7NkzyEA.png 700w\" width=\"791\" height=\"485\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe9\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe9\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div><figcaption class=\"qu qv op gg gh qw qx au b av aw ax\" data-selectable-paragraph=\"\">Price range chart for the Brand Samsung<\/figcaption><\/figure>\n<figure class=\"gb qh qi qj qk kw gg gh paragraph-image\">\n<div class=\"ql qm ag qn v qo\" tabindex=\"0\" role=\"button\">\n<div class=\"gg gh rc\">\n<div class=\"lb y ag lc\">\n<div class=\"rd le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*xaBkEyQBSa1LVEuhvJuq8A.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"779\" height=\"475\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe10\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe10\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/1169\/1*xaBkEyQBSa1LVEuhvJuq8A.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 700px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*xaBkEyQBSa1LVEuhvJuq8A.png 276w, https:\/\/miro.medium.com\/max\/828\/1*xaBkEyQBSa1LVEuhvJuq8A.png 552w, https:\/\/miro.medium.com\/max\/960\/1*xaBkEyQBSa1LVEuhvJuq8A.png 640w, https:\/\/miro.medium.com\/max\/1050\/1*xaBkEyQBSa1LVEuhvJuq8A.png 700w\" width=\"779\" height=\"475\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe11\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe11\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div><figcaption class=\"qu qv op gg gh qw qx au b av aw ax\" data-selectable-paragraph=\"\">Price range chart for the Brand Apple<\/figcaption><\/figure>\n<\/div>\n<\/div>\n<\/section>\n<\/div>\n<\/article>\n<div class=\"er fz fn lk v xt ri ln\" data-test-id=\"post-sidebar\">\n<div class=\"n p\">\n<div class=\"ai aj ak al am an ao v\">\n<div class=\"lo n t\">\n<div class=\"fz\">\n<div>\n<div class=\"rk af y\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>\n<div class=\"sa kw n t p\">\n<div class=\"y nx\">\n<div class=\"ti tj y tk\">\n<div class=\"n p\">\n<div class=\"ai aj ak al am ga ao v\">\n<div class=\"n o bn\">\n<p>AI Enthusiast<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"ui y tk nx\">\n<div class=\"n p\">\n<div class=\"go gp gq gr gs gt ao v\">\n<div class=\"gg gh gi y gj gk gl gm gn\">\n<div class=\"n p\">\n<div class=\"ai aj ak al am ga ao v\">\n<div class=\"v gu\">\n<div class=\"y\">\n<div class=\"o n\">\n<div>Sep 1, 2020<\/div>\n<\/div>\n<div><a class=\"cw dv\" href=\"https:\/\/byy3.com\/go\/?url=https:\/\/chithraprabhap.medium.com\/overloading-in-python-73e8ee51d93d?source=follow_footer---------0----------------------------\" rel=\"noopener\" rel=\"nofollow\" >Overloading in Python<\/a><\/div>\n<div><\/div>\n<div class=\"gv y\">\n<section class=\"cq gy gz cl ha\">\n<p id=\"46b4\" class=\"ht hu hc hv b hw he hx hy hh hz ia ib ic id ie if ig ih ii ij ik cq et\" data-selectable-paragraph=\"\">In Object Oriented programming approach the concept of polymorphism is about having a class objects in many forms. Polymorphism is of two types one is static polymorphism and the other is dynamic polymorphism.<\/p>\n<figure class=\"ca kw gg gh paragraph-image\">\n<div class=\"kx gg gh\">\n<div class=\"lb y ag lc\">\n<div class=\"ld le y\">\n<div class=\"er ky fv fp fm gu v en kz la\"><img loading=\"lazy\" decoding=\"async\" class=\"fv fp fm gu v lf lg as nb\" data-original=\"https:\/\/miro.medium.com\/max\/45\/1*WAaGvf9bC4J4xB5eQSQu9g.png?q=20\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" width=\"528\" height=\"271\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe12\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe12\" \/><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"mr ms fv fp fm gu v c\" data-original=\"https:\/\/miro.medium.com\/max\/792\/1*WAaGvf9bC4J4xB5eQSQu9g.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" sizes=\"auto, 528px\" srcset=\"https:\/\/miro.medium.com\/max\/414\/1*WAaGvf9bC4J4xB5eQSQu9g.png 276w, https:\/\/miro.medium.com\/max\/792\/1*WAaGvf9bC4J4xB5eQSQu9g.png 528w\" width=\"528\" height=\"271\" title=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe13\" alt=\"Product Analysis using Web Scraping Technique in Python open code\u63d2\u56fe13\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/figure>\n<p id=\"444f\" class=\"ht hu hc hv b hw he hx hy hh hz ia ib ic id ie if ig ih ii ca ik cq et\" data-selectable-paragraph=\"\">Python do not have compile time polymorphism directly, that is because python programs do not use compilation specific to the machine in which they run ,instead the python programs are compiled to be run on a python virtual machine, and hence compilation is not specific to the machine, which makes python portable across platforms,more easier to learn and machine independent ,the picture below gives an overview of the components used to convert a python language program to a running code. \u2026<\/p>\n<\/section>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<hr \/>\n<pre><span style=\"font-family: arial, helvetica, sans-serif;\">\r\nimport bs4<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">import pandas as pd<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">import numpy as np<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">import seaborn as sns<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">import matplotlib.pyplot as plt<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">from scipy import stats<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">import plotly_express as px<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">from urllib.request import urlopen as uReq<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">from bs4 import BeautifulSoup as soup\r\n<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">myurl = \"https:\/\/www.flipkart.com\/tablets\/pr?sid=tyy,hry&amp;marketplace=FLIPKART\"<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">uclient = uReq(myurl)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">page_html = uclient.read()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">uclient.close()<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">psoup = soup(page_html, \"html.parser\")<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">products_list = list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">prices_list = list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">ratings_list= list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">modelnames_list= list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">brandnames_list = list()<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">rams_list= list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">colors_list= list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">displays_list= list()<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">connectivities_list= list()<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">page_urls = list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">for containers in psoup.findAll('div',{'class':'_2MImiq'}):<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> page_href_list = containers.findAll('a',{'class':'ge-49M'})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #uncomment the below 2 lines to get all the search 10 pages<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #for a in a_list:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> # page_urls.append('https:\/\/www.flipkart.com'+ a['href'])<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #uncomment the below 2 lines to get single search page<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> page_href= page_href_list[0]<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> page_urls.append('https:\/\/www.flipkart.com'+ page_href['href'])<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">for url in page_urls:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> print(url)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> uclient = uReq(url)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> page_html = uclient.read()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> uclient.close()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> psoup = soup(page_html, \"html.parser\")<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> prod_urls = list()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">for containers in psoup.findAll('div',{'class':'_13oc-S'}):<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for a in containers:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> a_list = a.findAll('a',{'class':'_1fQZEK'})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #print(a_list['href'])<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #prod_urls.append('https:\/\/www.flipkart.com'+ a_list['href'])<\/span>\r\n <span style=\"font-family: arial, helvetica, sans-serif;\"> for a in a_list:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> prod_urls.append('https:\/\/www.flipkart.com'+ a['href'])<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for p_url in prod_urls:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> uclient = uReq(p_url)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> page_html = uclient.read()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> uclient.close()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> psoup = soup(page_html, \"html.parser\")<\/span>\r\n <span style=\"font-family: arial, helvetica, sans-serif;\">all_procuct_items = psoup.find('div', attrs={'class' : '_3k-BhJ'})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> all_procuct_items = all_procuct_items.findAll('tr', attrs={'class' : '_1s_Smc row'})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for procuct_item in all_procuct_items:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> dataname = procuct_item.findAll(\"td\", {\"class\": \"_1hKmbr col col-3-12\"})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> datadetails = procuct_item.findAll(\"td\", {\"class\": \"URwL2w col col-9-12\"})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> \"\"\"\r\n color = dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> display = dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> modelname = dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> connectivity = dict()<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for names in dataname:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> if( 'Name' in names.text):<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for details in datadetails:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> modelname['modelname'] = details.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> modelnames.append(details.text)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> elif( 'Color' in names.text):<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for details in datadetails:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> color['color'] = details.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> colors.append(details.text)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> elif(\"Display\" in names.text):<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for details in datadetails:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> display['display'] = details.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> displays.append(details.text)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> elif(\"Connectivity\" in names.text):<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for details in datadetails:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> connectivity['connectivity'] = details.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> connectivities.append(details.text)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> \"\"\"<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> container= psoup.findAll(\"div\",{\"class\":\"_1AtVbE col-12-12\"})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #container variable contains the html of product title which is stored in div tag and class is \"_1AtVbE col-12-12\"<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for product_item in container:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> product_dict = dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> rating_dict= dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> price_dict = dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> brandname_dict = dict()<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> n = product_item.findAll(\"span\",{\"class\":\"B_NuCI\"})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> p = product_item.findAll(\"div\",{\"class\":\"_30jeq3 _16Jk6d\"})<\/span>\r\n <span style=\"font-family: arial, helvetica, sans-serif;\"> r = product_item.findAll(\"div\",{\"class\":\"_2d4LTz\"})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for i in n:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> product_dict['name'] = i.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> strtmp = i.text.split(\" \")<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> brandname_dict['brandname'] = strtmp[0]<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> brandnames_list.append(strtmp[0])<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> products_list.append(i.text)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for j in p:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> jStr = j.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> jStr = jStr.replace(\"\u20b9\", \"\")<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> jStr = jStr.replace(\",\", \"\")<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> price_dict['price'] = int( jStr)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> prices_list.append(int( jStr))<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> for k in r:<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> #print (i.text)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> rating_dict['rating'] = k.text<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> ratings_list.append(k.text)<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">print (\"Number of items in the products list = \", len(products_list))<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">print (\"Number of items in the prices list = \", len(prices_list))<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">print (\"Number of items in the ratings list = \", len(ratings_list))<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">df = pd.DataFrame({'Brand':brandnames_list,'Price':prices_list,'Ratings':ratings_list,'ProductName':products_list})<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">df.to_csv ('export_products_dataframe.csv')<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">df['Price'] = df['Price'].astype(np.float)<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">sns.boxplot(x=df['Price'])<\/span>\r\n\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">sns.catplot(x = \"Price\", # x variable name<\/span> \r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> y = \"Brand\", # y variable name<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> hue = \"Ratings\", # group variable name<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\"> data = df, # dataframe to plot\r\n<\/span><span style=\"font-family: arial, helvetica, sans-serif;\"> kind = \"bar\")<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">df.groupby('Brand').plot(x='Brand', y='Price')<\/span>\r\n<span style=\"font-family: arial, helvetica, sans-serif;\">sns.barplot(x = 'Brand', y = 'Price', data = df)<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Web Scraping is one of the Data Scraping technique in w [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[402,401],"class_list":["post-863","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-scrapy","tag-scrapy"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=863"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/863\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}