The scripts below read an excel sheet and find order numbers on the page; when one is found the script will enter the corresponding tracking number, return to the first page (which is the same page it originally searched) and continue looking through the order numbers.
Can anyone tell me why the following scripts slow down considerably when returning to that page? For instance: The scripts will work extremely well and searches about 5 order numbers a second and enters the tracking number and submits it very quick.
When the script goes back to the pages with the unshipped orders it takes VERY long to search for more of them (maybe 1 every MINUTE)
The two scripts look like this:
list_of_files = glob.glob('F:/TrackingBot/GC/updater/*') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
wb = xlrd.open_workbook(latest_file)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
for i in range(sheet.nrows):
cell = sheet.cell(i, 3)
cty = cell.ctype
if cty == xlrd.XL_CELL_EMPTY:
continue
else:
po = (sheet.cell_value(i, 3))
tracking = (sheet.cell_value(i, 10))
wayfair = "CS"
wayfsubstring = wayfair in po
if wayfsubstring == True:
continue
print("SEARCHING FOR: ", po)
if driver.find_elements_by_link_text(po):
print("FOUND!!!!", po, tracking)
driver.find_element_by_link_text(po).click()
ups = "1Z"
isSubstring = ups in tracking
if isSubstring == True:
cprint('UPS TRACKING NUMBER', 'green')
driver.implicitly_wait(25)
confirm = driver.find_element_by_link_text("""Confirm shipment""")
confirm.click()
time.sleep(1)
driver.implicitly_wait(25)
trackingnum = driver.find_element_by_xpath("""//input[contains(@data-test-id,
'text-input-tracking-id')]""")
trackingnum.click()
trackingnum.send_keys(tracking)
driver.implicitly_wait(25)
driver.find_element_by_xpath("""(//input[@value='Confirm shipment'])[2]""").click()
time.sleep(3)
driver.refresh()
time.sleep(4)
continue
else:
cprint("NOT UPS TRACKING", "red")
period = "."
isSubstring2 = period in tracking
if isSubstring2 == True:
cprint('NJ SENT TRACKING NUMBER', 'yellow')
input("Type to GO")
driver.refresh()
time.sleep(4)
continue
else:
cprint('FEDEX FREIGHT TRACKING NUMBER', 'green')
input("Type to GO")
driver.refresh()
time.sleep(4)
continue
The code above is for Amazon and the code below is for shopify.
list_of_files = glob.glob('F:/TrackingBot/GC/updater/*') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
wb = xlrd.open_workbook(latest_file)
sheet = wb.sheet_by_index(0)
sheet.cell_value(0, 0)
for i in range(sheet.nrows):
cell = sheet.cell(i, 3)
cty = cell.ctype
if cty == xlrd.XL_CELL_EMPTY:
continue
else:
po = (sheet.cell_value(i, 3))
tracking = (sheet.cell_value(i, 10))
wayfair = "CS"
wayfsubstring = wayfair in po
if wayfsubstring == True:
continue
print("SEARCHING FOR: ", po)
if driver.find_elements_by_link_text(po):
print("FOUND!!!!", po, tracking)
driver.find_element_by_link_text(po).click()
ups = "1Z"
isSubstring = ups in tracking
if isSubstring == True:
cprint('UPS TRACKING NUMBER', 'green')
driver.implicitly_wait(25)
mark = driver.find_element_by_xpath("""//*[@id="unfulfilled-card-0"]/div[3]/div/div/a[1]""")
mark.click()
driver.implicitly_wait(25)
trackingnum = driver.find_element_by_xpath("""//*[
@id="fulfillments_0_shipping_options_tracking_number"]""")
trackingnum.click()
trackingnum.send_keys(tracking)
driver.implicitly_wait(25)
driver.find_element_by_xpath("""(//button[contains(@type,'submit')])[1]""").click()
driver.implicitly_wait(25)
driver.find_element_by_xpath("""(//span[contains(.,'Orders')])[2]""").click()
time.sleep(2)
continue
else:
cprint("NOT UPS TRACKING", "red")
period = "."
isSubstring2 = period in tracking
if isSubstring2 == True:
cprint('NJ SENT TRACKING NUMBER', 'yellow')
input("Type to GO")
continue
else:
cprint('FEDEX FREIGHT TRACKING NUMBER', 'green')
input("Type to GO")
continue
I've tried using driver.refresh() , waiting in case the page isn't fully loaded etc.
Any advice is appreciated!