File tree 1 file changed +44
-0
lines changed
1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+
3
+ from bs4 import BeautifulSoup
4
+ url = "https://www.amazon.in/gp/bestsellers/computers/1375424031"
5
+
6
+ respose = requests .get (url )
7
+
8
+ page_content = respose .text
9
+
10
+ doc = BeautifulSoup (page_content ,'html.parser' )
11
+
12
+ # _cDEzb_p13n-sc-css-line-clamp-3_g3dy1
13
+ laptop_title_tag = doc .find_all ('div' ,{"class" : "zg-grid-general-faceout" })
14
+
15
+ #print(laptop_title)
16
+
17
+ def get_laptop_title (doc ):
18
+ laptop_title_tag = doc .find_all ('div' ,{"class" : "zg-grid-general-faceout" })
19
+ laptop_titles = []
20
+ for tag in laptop_title_tag :
21
+ try :
22
+ title = tag .find ('span' )
23
+ laptop_titles .append (title .text )
24
+ except :
25
+ laptop_titles .append ("No laptop found" )
26
+ return laptop_titles
27
+
28
+ print (get_laptop_title (doc )[:10 ]) # this will give top 10 laptop
29
+
30
+ import pandas as pd
31
+ # making csv file
32
+ def get_Csv (doc ):
33
+ all_laptop = {'Model Name' : []}
34
+ all_laptop ["Model Name" ]= get_laptop_title (doc )
35
+ return all_laptop
36
+
37
+ csv_file = pd .DataFrame .from_dict (get_Csv (doc ), orient = 'index' )
38
+ csv_file = csv_file .transpose ()
39
+ csv_file .to_csv ('Top Ten Selling Laptop.csv' ,index = None )
40
+
41
+
42
+
43
+
44
+
You can’t perform that action at this time.
0 commit comments