嗨,我有一个selenium python脚本,它将密钥(url和id)发送到线程中的页面...这里是代码
class myThread (threading.Thread):
def __init__(self, url, idd):
threading.Thread.__init__(self)
self.url = url
self.idd = idd
def run(self):
runScript(self.url, self.idd)
print "Exiting " + self.url
def runScript(url, idd):
driver = webdriver.PhantomJS(executable_path='/home/wasif/public_html/phantomjs')
try:
driver.set_window_size(1120, 550)
driver.get("http://example.com")
driver.find_element_by_id('url').send_keys(str(url))
driver.find_element_by_id('id').send_keys(str(idd))
tble = "urls%s" % (tbl)
driver.find_element_by_id('table').send_keys(str(tble))
driver.find_element_by_id("submit").click()
#print driver.page_source
driver.quit()
except:
driver.quit()
try:
sql = "SELECT * FROM urls"
cursor.execute(sql)
print "TOTAL RECORDS: "+str(cursor.rowcount)
results = cursor.fetchall()
count = 0;
for row in results:
try:
domain = row[1]
idd = row[0]
myThread(domain, idd).start()
time.sleep(delay)
except Exception, e:
print "error running crawler: "+str(e)
except Exception,e:
print str(e)
db.close()
print "Exiting Main Thread"
有什么办法可以在10秒后停止新线程,如果它没有完成或者在10秒后停止driver
?任何帮助将不胜感激