Saif Ali
Saif Ali

Reputation: 427

How to Speed Up Interpreting Speed in Python?

I have a script in python that takes excel sheet and reads it stores in a tuple, then using selenium web-driver it injects the values in the web form, but i think its a bit slow approach to do so, isn't there any way the whole code executes in an instant without going line by line.

Maybe making a separate async thread for each line?

Here are some of the lines:

self.browser.find_element_by_xpath(
                "//div[@data-id='Year']//select/option[text()='" + str(int(year)) + "']").click()
            self.small_wait()

            self.browser.find_element_by_xpath(
                "//div[@data-id='Make']//select/option[text()='" + str(make) + "']").click()
            #self.medium_wait()
            if re.search(r'(?<=\s\d)[-](?=\d)', str(model)) != None:
                rgx = re.compile(r'(?<=\d)[-](?=\d)')
                model = str(rgx.sub('.', str(model)))
            self.browser.find_element_by_xpath(
                "//div[@data-id='Model']//select/option[text()='" + str(model) + "']").click()
            #self.small_wait()

            self.browser.find_element_by_xpath(
                "//div[@data-id='PrimaryUse']//select/option[text()='Commute To/From Work']").click()
            #self.small_wait()
            self.browser.find_element_by_xpath("//input[@name='bq_add_clone_Vehicle_1'][@value='No']").click()
            #self.small_wait()

            self.browser.find_element_by_xpath(
                "//div[@data-id='CoverageType']//select/option[text()='Standard Protection']").click()

All in one any way to optimise or speed the process up? it takes an average of 15 seconds to process one form it has like 10 fields , nothing fancy.

Thanks

Upvotes: 0

Views: 79

Answers (1)

Louis Saglio
Louis Saglio

Reputation: 1148

Find out which POST request is made when you submit the form. Then send a POST request directly without using selenium. It will dramatically improve your script performance.

Upvotes: 1

Related Questions