Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

python - How do I make this bot refresh when it see's that the object is sold out?

So I made this auto-checkout bot so that I could get one of the ps5 or some product on best buy website on pycharm using Chromedriver and selenium.

    from selenium import webdriver
import time driver = webdriver.Chrome(executable_path=r'C:UsersabdulDownloadschromedriver.exe')

driver.get("https://www.bestbuy.com/site/macbook-air-13-3-laptop-apple-m1-chip-8gb-memory-256gb-ssd-latest-model-space-gray/5721600.p?skuId=5721600")


time.sleep(5)


addtocartbutton = driver.find_element_by_xpath('/html/body/div[3]/main/div[2]/div/div[1]/div[3]/div[2]/div/div[2]/div[1]/div/div/div/button')
addtocartbutton.click()

time.sleep(10)

gotocartbutton = driver.find_element_by_xpath('/html/body/div[7]/div/div[1]/div/div/div/div/div[1]/div[3]')
gotocartbutton.click()

time.sleep(2)

shippingbutton = driver.find_element_by_xpath('/html/body/div[1]/main/div/div[2]/div[1]/div/div[2]/div[1]/section[1]/div[4]/ul/li/section/div[2]/div[2]/form/div[2]/fieldset/div[2]/div[1]/div/div/div/input')
shippingbutton.click()


checkoutbutton = driver.find_element_by_xpath('/html/body/div[1]/main/div/div[2]/div[1]/div/div[2]/div[1]/section[2]/div/div/div[3]/div[1]/div[1]')
checkoutbutton.click()

time.sleep(3)

emailfill = driver.find_element_by_xpath('/html/body/div[1]/div/section/main/div[1]/div/div/div/div/form/div[1]/div/input')
emailfill.send_keys('myemailwouldgohere')

paswrdfill = driver.find_element_by_xpath('/html/body/div[1]/div/section/main/div[1]/div/div/div/div/form/div[2]/div/input')
paswrdfill.send_keys('password')

signinbutton = driver.find_element_by_xpath('/html/body/div[1]/div/section/main/div[1]/div/div/div/div/form/div[3]')
signinbutton.click()

time.sleep(3)

firstname = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[1]/div/div/section/div[2]/div[1]/section/section/div[1]/label/div/input')
firstname.send_keys('Abdullah')

lastname = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[1]/div/div/section/div[2]/div[1]/section/section/div[2]/label/div/input')
lastname.send_keys('Nizar')

address = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[1]/div/div/section/div[2]/div[1]/section/section/div[3]/label/div[2]/div/div/input')
address.send_keys('adress')

city = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[1]/div/div/section/div[2]/div[1]/section/section/div[5]/div/div[1]/label/div/input')
city.send_keys('city')

state = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[1]/div/div/section/div[2]/div[1]/section/section/div[5]/div/div[2]/label/div/div/select')
state.click()
state.send_keys('mi')

zipcode = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[1]/div/div/section/div[2]/div[1]/section/section/div[6]/div/div[1]/label/div/input')
zipcode.send_keys('48336')

paymentbutton= driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[2]/form/section/div/div[2]/div/div/button')
paymentbutton.click()

time.sleep(5)

cardfill = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[3]/div/section/div[1]/div/section/div[1]/div/input')
cardfill.send_keys('11111111111111')

placeorderbutton = driver.find_element_by_xpath('/html/body/div[1]/div[2]/div/div[2]/div[1]/div[1]/main/div[2]/div[3]/div/section/div[4]/button')
placeorderbutton.click()

I want to make it refresh when it sees that the product is not in stock every 5 secs. I do not know how to do that. Otherwise is just runs the code and checks it out. Can anyone help?

question from:https://stackoverflow.com/questions/66052177/how-do-i-make-this-bot-refresh-when-it-sees-that-the-object-is-sold-out

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...