[英]How to Speed Up Interpreting Speed in Python?
我在python中有一个脚本,它使用Excel工作表并将其存储在一个元组中,然后使用Selenium Web驱动程序将其注入Web表单中的值,但我认为这样做有点慢,没有整个代码无需立即执行就可以立即执行的方式。
也许为每行创建一个单独的异步线程?
以下是一些代码行:
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()
以任何一种方式优化或加快流程吗? 处理一种具有10个字段的表格的平均时间为15秒,一点也不花哨。
谢谢
提交表单时,找出发出哪个POST请求。 然后不使用硒直接发送POST请求。 它将大大提高脚本性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.