multithreading - Keeping track of url while redirecting using threading with Selenium in python -
i have url has chain of redirection, upto 3 i.e. leads url , leads 1 until happens thrice.
i want close browser last page begins loading. know url has been reached when domain changed specific url. trying achieve using driver.current_url
threading.
i have implemented threading class as:
class driverthread (threading.thread): def __init__(self, threadid, driver): threading.thread.__init__(self) self.threadid = threadid self.driver = driver; def run(self): print "initiated thread: " + str(self.threadid); while true: #here problem lk=str(self.driver.current_url); try: if lk.find('myhostname.com',lk.index('://')+2,lk.index('/',lk.index('://')+4))>=0: sleep(1); else: #quits driver once link has redirected destination url print "visited"; self.driver.quit(); break; except valueerror: sleep(1); pass;
calling same as:
driver = webdriver.chrome(chrome_options=chrome_options); driverth = driverthread(id,driver) driverth.start(); driver.get(link) driverth.join();
the problem line lk=str(self.driver.current_url)
. when run script error stating cannotsendrequest
know due issue http lib. according me happens because thread keeps on checking driver.current_url
update when driver.get(link)
called. no sooner function called thread gives error cannotsendrequest
because getting link now.
Comments
Post a Comment