Upload best_seller.py
Browse files- best_seller.py +69 -0
best_seller.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
def get_items(mydivs):
|
3 |
+
Best_Sellers = {}
|
4 |
+
ListItems = []
|
5 |
+
BS = ""
|
6 |
+
LoL_ListItems = []
|
7 |
+
Items = []
|
8 |
+
Item = 0
|
9 |
+
for track in mydivs:
|
10 |
+
str_track = str(track)
|
11 |
+
if ("aria-label" in str_track):
|
12 |
+
print("-----------------------------------------")
|
13 |
+
#
|
14 |
+
Key = track['aria-label']
|
15 |
+
Key = Key.replace("Best Sellers in ", "")
|
16 |
+
Key = Key.replace(" - See More", "")
|
17 |
+
print(Key)
|
18 |
+
#
|
19 |
+
Items.append(Key)
|
20 |
+
if (LoL_ListItems):
|
21 |
+
if (len(LoL_ListItems) == 6):
|
22 |
+
Best_Sellers[Items[Item]] = LoL_ListItems
|
23 |
+
BS = Key
|
24 |
+
LoL_ListItems = []
|
25 |
+
Item = Item + 1
|
26 |
+
else:
|
27 |
+
if ("data-rows" in str_track and "href" in str_track):
|
28 |
+
start = str_track.find("data-rows=") + len("data-rows") + 5
|
29 |
+
end = str_track.find("</div")
|
30 |
+
Product = str_track[start:end]
|
31 |
+
li = list(Product.split("-"))
|
32 |
+
Link = "https://www.amazon.com/" + track['href']
|
33 |
+
#
|
34 |
+
ListItems.append(Key)
|
35 |
+
ListItems.append(li)
|
36 |
+
# ListItems.append(Link)
|
37 |
+
#
|
38 |
+
if ("title" in str_track):
|
39 |
+
ListItems.append(track['title'])
|
40 |
+
if ("_p13n-zg-list-carousel-desktop_price_p13n-sc-price__3mJ9Z" in str_track):
|
41 |
+
Exp = "_p13n-zg-list-carousel-desktop_price_p13n-sc-price__3mJ9Z"
|
42 |
+
#
|
43 |
+
end_sep = "</span"
|
44 |
+
result = []
|
45 |
+
tmp = str_track.split(Exp)
|
46 |
+
for par in tmp:
|
47 |
+
if (end_sep in par):
|
48 |
+
result.append(par.split(end_sep)[0])
|
49 |
+
if (len(result) == 2):
|
50 |
+
Result = str(result[0][2:len(result[0])]) + " - " + str(result[1][2:len(result[1])])
|
51 |
+
else:
|
52 |
+
Result = str(result[0][2:len(result[0])])
|
53 |
+
Result1 = list(Result.split("-"))
|
54 |
+
ListItems.append(Result1)
|
55 |
+
#
|
56 |
+
LoL_ListItems.append(ListItems)
|
57 |
+
ListItems = []
|
58 |
+
#
|
59 |
+
listoflist_1 = []
|
60 |
+
Best_Sellers[Items[Item]] = LoL_ListItems
|
61 |
+
print("********************************************************")
|
62 |
+
for key1 in Best_Sellers:
|
63 |
+
print(key1, "-", len(Best_Sellers[key1]))
|
64 |
+
print("********************************************************")
|
65 |
+
# for key in Best_Sellers:
|
66 |
+
# for listoflist in Best_Sellers[key]:
|
67 |
+
# listoflist_1.append(listoflist)
|
68 |
+
# print(Best_Sellers)
|
69 |
+
return Best_Sellers
|