-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (45 loc) · 2.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from flipkart_scrapper import flipkartSearch
from amazon_scrapper import amazonSearch
from prettytable import PrettyTable
header_flipkart = {
"user-agent" : "Mozilla/5.0 (Linux; Android 6.0.1; SAMSUNG SM-G570Y Build/MMB29K)",
"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
}
header_amazon = {
"user-agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0",
"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
}
name = input("Enter the name of the product to search : ")
n = int(input("Enter the number of search results required : "))
print("Searching Flipkart ....")
flipkartProduct = flipkartSearch(name, header_flipkart)
flipkart_names_all = flipkartProduct.getNames()
flipkart_prices_all = flipkartProduct.getPrices()
flipkart_names = []
flipkart_prices = []
for i in range(0,min(n,len(flipkart_names_all))):
if(flipkart_names_all[i] is not None):
flipkart_names.append(flipkart_names_all[i])
for i in range(0,min(n,len(flipkart_prices_all))):
if(flipkart_prices_all[i] is not None):
flipkart_prices.append(flipkart_prices_all[i])
flipkart_table = PrettyTable(align='l')
flipkart_table.field_names = ["Product Name", "Price (INR)"]
for name, price in zip(flipkart_names, flipkart_prices):
flipkart_table.add_row([name, price])
print(flipkart_table)
print("Searching Amazon ....")
amazonProduct = amazonSearch(name, header_amazon)
amazon_names_all = amazonProduct.getNamesAndPrices()["names"]
amazon_prices_all = amazonProduct.getNamesAndPrices()["prices"]
amazon_names = []
amazon_prices = []
for i in range(0,min(n,len(amazon_names_all))):
amazon_names.append(amazon_names_all[i])
for i in range(0,min(n,len(amazon_prices_all))):
amazon_prices.append(amazon_prices_all[i])
amazon_table = PrettyTable(align='l')
amazon_table.field_names = ["Product Name", "Price (INR)"]
for name, price in zip(amazon_names, amazon_prices):
amazon_table.add_row([name, price])
print(amazon_table)