I can not run code after the loop is [closed]

4

I'm using selenium as a crawler on a website. I have no experience with python.

Here I create a dataframe with the data of a .csv

df = pd.DataFrame.from_csv(
    'tabela_etickets_copa3.csv',
    columns = header
    )

I open the browser, I go to the site, I find the elements and I set my variables

driver = webdriver.Firefox()
driver.get("xxxxxxx")

bref = driver.find_element_by_name("ctl00$SPWebPartManager1$g_1eba1641_45a3_4029_be3a_175e90e68a47$input_manage_num_reservation")
lname = driver.find_element_by_name("ctl00$SPWebPartManager1$g_1eba1641_45a3_4029_be3a_175e90e68a47$input_manage_lastname")
botao = driver.find_element_by_xpath("//button[text()='Continuar']")

Finally, I looped with for to get the items from .csv , enter the site and press enter

for index, row in df.iterrows():
    lname.send_keys(row['PAX'].rsplit("/",1)[0] 
    botao.send_keys(Keys.RETURN)
    driver.close()

I'm having this error:

    botao.send_keys(Keys.RETURN)
        ^
SyntaxError: invalid syntax

What I understood here is that most commands after for do not work. Can anyone suggest me anything?

    
asked by anonymous 13.05.2015 / 20:27

1 answer

2

Syntax error means that the Python interpreter can not recognize your program as valid Python code. Usually this means that you have some symbol or reserved word missing (or missing) in your program or some indentation error. Syntax errors are something that the interpreter detects before attempting to run your program. It does not make any difference what functions you called or what values you put in the variables - these other possible errors are only detected when your program is running.

In your case, a ) is missing on this line:

lname.send_keys(row['PAX'].rsplit("/",1)[0] 

I think the correct one would be

lname.send_keys(row['PAX'].rsplit("/",1)[0])

The reason for the error being pointed out in the next line is that the parser continues to process the program by looking for more arguments to the send_keys, separated by commas.

lname.send_keys(row['PAX'].rsplit("/",1)[0]
    ,arg2, arg3)

As the next line did not begin with a comma, it complained and gave a syntax error.

    
13.05.2015 / 20:57