0% found this document useful (0 votes)
22 views10 pages

Code of The Project

The document contains code to scrape product details (name, price, description) of an iPhone 12 from multiple e-commerce websites (Flipkart, GadgetsNow, Sangeetha Mobiles) using Selenium. It then compares the prices to determine which site offers the lowest price. If Flipkart is lowest, it adds the item to cart and fills out a dummy checkout form. Similar logic is used if GadgetsNow or Sangeetha Mobiles offer the lowest price.

Uploaded by

Abhishek kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views10 pages

Code of The Project

The document contains code to scrape product details (name, price, description) of an iPhone 12 from multiple e-commerce websites (Flipkart, GadgetsNow, Sangeetha Mobiles) using Selenium. It then compares the prices to determine which site offers the lowest price. If Flipkart is lowest, it adds the item to cart and fills out a dummy checkout form. Similar logic is used if GadgetsNow or Sangeetha Mobiles offer the lowest price.

Uploaded by

Abhishek kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# IMPORTING LIBRARIES AND LOADING DRIVERS

from selenium import webdriver

from [Link] import By

from [Link] import Options

from [Link] import wait

import time

options=Options()

options.add_experimental_option("detach", True)

driver = [Link](options=options)

# FUNCTION TO CONVERT STRING INTO PRICE OF THE ITEM

def extract_price(text):
price_str = ""
text_split = [Link](".")
for char in text_split[0]:
try:
int(char)
price_str += char
except Exception as e:
continue
return int(price_str)
# FETCHING THE DETAILS OF ITEMS FROM FLIPKART

# Locating the item from the Flipkart Site.

[Link]('[Link] black 256 gb/p/itm68421fa1c1121?


pid=MOBFWBYZ7CR9FRHZ&lid=LSTMOBFWBYZ7CR9FRHZNVRHNR&marketplace=FLIPK
ART&q=iphone12&store=tyy
%2F4io&srno=s_1_1&otracker=search&otracker1=search&fm=organic&iid=a421f941-aad1-
48f3-b6f6-
[Link]&ppt=hp&ppn=homepage&ssid=hqatg1buds
0000001709962435415&qH=ad588135f239b88b')

# Fetching the item from the Flipkart Site.

flipkart_item_name=driver.find_element([Link],
"/html/body/div[1]/div/div[3]/div[1]/div[2]/div[2]/div/div[1]/h1/span").text

flipkart_item_cost=driver.find_element([Link],
"/html/body/div[1]/div/div[3]/div[1]/div[2]/div[2]/div/div[4]/div[1]/div/div[1]").text

flipkart_price = extract_price(flipkart_item_cost)

flipkart_item_description=driver.find_element([Link],
"/html/body/div[1]/div/div[3]/div[1]/div[2]/div[8]/div[1]/div/div[2]").text

# Printing the item’s values from the Flipkart Site.

print('The cost of', flipkart_item_name, 'on flipkart is :', flipkart_price)

print('the description of the item is :')


print(flipkart_item_description)
# FETCHING THE DETAILS OF ITEMS FROM GADGETSNOW

# Locating the item from the Flipkart Site.

[Link]('[Link]
ram-/10021/p_G201794?
gad_source=1&gclid=EAIaIQobChMI7qbuw8zmhAMVe6tmAh3FjgmEEAQYAiABEgLWwfD_B
wE')

# Fetching the item from the GadgetsNow Site.

gadgetnow_item_name=driver.find_element([Link],
"/html/body/div[1]/div[2]/div[5]/div[1]/div/div[1]/div[1]/h1").text

gadgetnow_item_cost=driver.find_element([Link],
"/html/body/div[1]/div[2]/div[5]/div[1]/div/div[1]/div[2]/div[1]/span[1]").text

gadgetnow_price = extract_price(gadgetnow_item_cost)

gadgetnow_item_description=driver.find_element([Link],
"/html/body/div[1]/div[2]/div[5]/div[1]/div/div[3]/div[2]/div[1]/div[3]").text

# Printing the item’s values from the GadgetsNow Site.

print('The cost of', gadgetnow_item_name, 'on gadget now is :', gadgetnow_price)

print('the description of the item is :')

print(gadgetnow_item_description)
# FETCHING THE DETAILS OF ITEMS FROM SANGEETHA MOBILES

[Link]('[Link]
Apple/8510?utm_source=google&utm_campaign=Apple-PerformanceMax-Mobile-
Scaling&gad_source=1&gclid=EAIaIQobChMIpJP38c7mhAMVE6dmAh0WBQLSEAQYASABE
gIbPvD_BwE')

# Fetching the item from the Sangeetha Mobile Site.

sangeeta_item_name=driver.find_element([Link],
"/html/body/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[2]/h1").text

sangeeta_item_cost=driver.find_element([Link],
"/html/body/div/div/div[2]/div/div[1]/div/div[2]/div[1]/div/div[2]/div[3]/div[1]/div[1]").text

sangeeta_price = extract_price(sangeeta_item_cost)

sangeeta_item_description=driver.find_element([Link],
"/html/body/div/div/div[2]/div/div[1]/div/div[2]/div[12]").text

# Printing the item’s values from the GadgetsNow Site.

print('The cost of', sangeeta_item_name, 'on Sangeeta is :', sangeeta_price)

print('the description of the item is :')

print(sangeeta_item_description)
# CODE TO FIND THE SITE PROVIDING MINIMUM COST IF FLIPKART PRICE IS LOWEST

if flipkart_price < gadgetnow_price:

if flipkart_price < sangeeta_price:

print('Flipkart has lowest value')

[Link](3)

[Link]('[Link]
pid=MOBFWBYZ7CR9FRHZ&lid=LSTMOBFWBYZ7CR9FRHZNVRHNR&marketplace=F
LIPKART&q=iphone12&store=tyy
%2F4io&srno=s_1_1&otracker=search&otracker1=search&fm=organic&iid=a421f941-
aad1-48f3-b6f6-
[Link]&ppt=hp&ppn=homepage&ssid=hqatg1
buds0000001709962435415&qH=ad588135f239b88b')

[Link](3)

driver.find_element([Link],
"/html/body/div[1]/div/div[3]/div[1]/div[1]/div[2]/div/ul/li[1]/button").click()

[Link](2)

driver.find_element([Link],
"/html/body/div[1]/div/div[2]/div/div[1]/div[1]/div/div[3]/div/form/button").click()

[Link](2)

driver.find_element([Link],
"/html/body/div/div/div[2]/div/div[1]/div[1]/div/div/div/div/div[1]/div/form/div[1]/
input").send_keys("shlok.abhishek127@[Link]")

[Link](2)

driver.find_element([Link],
"/html/body/div/div/div[2]/div/div[1]/div[1]/div/div/div/div/div[1]/div/form/div[3]/button").click()
# CODE TO LOGIN AND PLACING AN ORDER IN DUMMY SITE

# Tracing the site location.

[Link]('[Link]

[Link](3)

# Logging in into the site with Username and Password.

driver.find_element([Link],
"/html/body/div/div/div[2]/div[1]/div/div/form/div[1]/input").send_keys('standard_user')

driver.find_element([Link],
"/html/body/div/div/div[2]/div[1]/div/div/form/div[2]/input").send_keys('secret_sauce'

driver.find_element([Link], "/html/body/div/div/div[2]/div[1]/div/div/form/input").click()

[Link](3)

# Adding the element into Cart.

driver.find_element([Link],
"/html/body/div/div/div/div[2]/div/div/div/div[1]/div[2]/div[2]/button").click()

[Link](3)

driver.find_element([Link], "/html/body/div/div/div/div[1]/div[1]/div[3]/a").click()
[Link](3)

driver.find_element([Link], "//html/body/div/div/div/div[2]/div/div[2]/button[2]").click()
# Submitting the Detail of Buyer.

driver.find_element([Link],
"/html/body/div/div/div/div[2]/div/form/div[1]/div[1]/input").send_keys("Abhishek")

river.find_element([Link],
"/html/body/div/div/div/div[2]/div/form/div[1]/div[2]/input").send_keys("Kumar")

driver.find_element([Link],
"/html/body/div/div/div/div[2]/div/form/div[1]/div[3]/input").send_keys("110044")

[Link](3)

# Placing the Order.

driver.find_element([Link], "/html/body/div/div/div/div[2]/div/form/div[2]/input").click()
[Link](5)

driver.find_element([Link], "/html/body/div/div/div/div[2]/div/div[2]/div[9]/button[2]").click()
[Link]()
# CODE TO FIND THE SITE PROVIDING MINIMUM COST IF GADGETNOW PRICE IS
LOWEST

if flipkart_price > gadgetnow_price:

if gadgetnow_price < sangeeta_price

print('Gadgetnow has lowest value')

[Link](3)

[Link]('[Link]
gb-ram-/10021/p_G201794?
gad_source=1&gclid=EAIaIQobChMI7qbuw8zmhAMVe6tmAh3FjgmEEAQYAiABEgLWwf
D_BwE')

[Link](3)

driver.find_element([Link],
"/html/body/div[1]/div[2]/div[5]/div[1]/div/div[3]/div[2]/div[2]/div[2]/span/a").click()

[Link](3)

driver.find_element([Link],
"/html/body/div[20]/div[2]/div/div/form/div[3]/div[2]/div[2]/a").click()

[Link](3)

[Link]()
# CODE TO FIND THE SITE PROVIDING MINIMUM COST IF SANGEETHA MOBILES
PRICE IS LOWEST

if sangeeta_price < gadgetnow_price:

if sangeeta_price < flipkart_price:

print('SANGEETHA MOBILES has lowest value')

[Link](3)

[Link]('[Link]
256gb-mgjg3hna/8510')

[Link](3)

[Link]()

You might also like