Home > other >  Python circulation anomaly, how to skip the abnormal continue?
Python circulation anomaly, how to skip the abnormal continue?

Time:04-15

Below is a code I wrote, is my excel in data sources are listed in table testleadtime purpose port code and its corresponding to the number of days of shipping, need to update company designated Intranet data,

When running cycle, go wrong?

For example, the following is the first column and the second column in the Excel table, POD is the port of destination, TL is transportation days

Run Python, if in accordance with the form below to extract data, fill to the corresponding address, no problem
Because it is over, JPMOJ JPHKT JPUKB, JPNGO have maintenance in the website backstage,

POD LT
JPHKT 1
JPMOJ 2
JPUKB 3
JPNGO 4

But if I am in the excel table of raw data, insert the background did not maintain a url of the port of destination the DPRK

I this for loop is quite so is interrupted, or code input POD after "the DPRK" points the find no results

POD LT
JPHKT 1
JPMOJ 2
The DPRK 5
JPUKB 3
JPNGO 4

My question is, how to change my code, so that cycle over the DPRK, continue to implement the next JPUKB till the end?

Below is I write the original code

[b] [b] # import related excel
The import pandas as pd
data=https://bbs.csdn.net/topics/pd.read_excel (" testleadtime. XLSX ")

The import numpy as np

Data. Dropna (inplace=True)
Data. Reset_index ()

Module # initial steps, landing ALS, open belong to
The from the selenium import webdriver
Wd=webdriver. Chrome ()
Wd. Implicitly_wait (10)
The from the selenium. Webdriver. Support. The UI import the Select
From the time the import sleep
# landing ALS3
Wd. Get (" http://gsltest.upm-kymmene.com/ALS3S/run/app/home/")
# choose SCCT
Element=wd. Find_element_by_xpath ("/HTML/body/table/tbody/tr [3]/td/table/tbody/tr/td [1]/div [2]/div [1]/table/tbody/tr/td [2]/a ")

element. The click ()# choose legs
Element=wd. Find_element_by_xpath ("/HTML/body/table/tbody/tr [3]/td/table/tbody/tr/td [1]/div [2]/div [3]/table/tbody/tr/td [2]/a ")

element. The click ()

# cycle running process
For I in range (len (data. The index)) :
# choose the List of legs
Element=wd. Find_element_by_xpath ("/HTML/body/table/tbody/tr [3]/td/table/tbody/tr/td [1]/div [2]/div [4]/table/tbody/tr/td [2]/a ")

element. The click ()# choose SEA
Select=select (wd. Find_element_by_css_selector (" [name='transportmode'] "))
Select. Select_by_value (" SEA ")
# enter POL
Wd. Find_element_by_css_selector (" [name='picklocation'] "). The send_keys (" SG01 ")
# enter POD
Wd. Find_element_by_css_selector (" [name='droplocation'] "). The send_keys (data. The iloc [I, 0])
# click find
Element=wd. Find_element_by_xpath ("/HTML/body/table/tbody/tr [3]/td/table/tbody/tr/td [2]/div/form/div [3]/input ")

element. The click ()
# click legs ID
Element=wd. Find_element_by_xpath ("/HTML/body/table/tbody/tr [3]/td/table/tbody/tr/td [2]/div/form/table/tbody tr [1] [2]/td/a ")

element. The click ()# enter business duration
Wd. Find_element_by_css_selector (" [name='averageduration'] "). The clear ()
Wd. Find_element_by_css_selector (" [name='averageduration'] "). The send_keys (STR (data. The iloc [I, 1)))
# click save
Element=wd. Find_element_by_xpath ("/HTML/body/table/tbody tr [3]/td/table/tbody/tr/td [2]/div/div [2]/form/div [3]/table/tbody/tr/td [1]/input ")

element. The click ()Sleep (2)




CodePudding user response:

CodePudding user response:

At this stage encountered an error:

CodePudding user response:

Should be able to use the try the except wrapped may have abnormal, data processing, the continue without data

CodePudding user response:

The try, except, pass, continue, or all kinds of wrong:

I'll describe the problem, I am after step # by clicking on the find, because is the POD entered does not exist, so click # legs ID error, need to skip the error at this time, back to the beginning of # choose the list of legs, to continue to cycle





CodePudding user response:

Still won't do:

CodePudding user response:


Bosses, I this mistake how to change

CodePudding user response:

Put excpet some sleep after (2)

  • Related