Skip to content

Commit 3b1db84

Browse files
authored
Merge pull request #2 from codeasarjun/codeasarjun-patch-1
fixed script for bestSellingLaptop
2 parents 7a63527 + 6250acd commit 3b1db84

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+

0 commit comments

Comments
 (0)