I can’t run code after the cycle is

Asked

Viewed 76 times

4

I am using Selenium as 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
    )

open the browser, enter the site, find the elements and Seto 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 spin a loop with for to pick up items from .csv, insert into the site and squeeze enter

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

I’m making that mistake:

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

What I understand here is that most commands after the for do not work. Can anyone suggest me something ?

  • I think you’re missing one ) here: lname.send_keys(row['PAX'].rsplit("/",1)[0]

  • 1

    @Lucascobino Your question is being closed because apparently it is only a typo, as demonstrated by Sergio. Can you confirm whether this is the case or not? If it is not, please edit your question to clarify this point and avoid closing (or reopen if the question has already been closed).

  • That’s right, you can close.

1 answer

2


Syntax error means that the Python interpreter cannot recognize your program as valid Python code. Usually this means that you have some keyword or keyword missing (or left over) in your program or some indentation error. Syntax errors are something the interpreter detects before trying to run your program. It makes no difference which functions you called or which values you put in the variables - these other possible errors are only detected when your program is running for real.

In your case, you’re missing one ) along those lines:

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

I think the right thing would be

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

The reason the error is pointed at the next line is that the parser continues to process the program looking for more arguments for send_keys, separated by comma.

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

As the pàoxima line did not start with comma, he complained and gave a syntax error.

  • It really was that, after that gave an error in the columns = header when I load . csv.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.