Created
November 1, 2013 23:38
-
-
Save objarni/7273639 to your computer and use it in GitHub Desktop.
Hack to run multiple selenium browser at the same time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import time | |
from browserdriver import BrowserDriver | |
def readfile(fname): | |
with open(fname) as f: | |
content = f.read() | |
#print("Read value " + content + " from file " + fname) | |
return content | |
def writefile(fname, content): | |
print('Writing value ' + content + ' to file ' + fname) | |
with open(fname, 'w') as f: | |
f.write(content) | |
fname = 'click_value.txt' | |
def readvalue(): | |
return readfile(fname) | |
def writevalue(value): | |
writefile(fname, value) | |
def worker(): | |
browser = BrowserDriver('http://www.wikipedia.org') | |
oldvalue = '' | |
while True: | |
value = readvalue() | |
if value=='QUIT': | |
break | |
if value==oldvalue: | |
time.sleep(1) | |
continue | |
try: | |
browser.click_link(value) | |
except: | |
pass | |
oldvalue = value | |
browser.close() | |
if __name__ == '__main__': | |
writevalue('') | |
jobs = [] | |
for i in range(3): | |
p = multiprocessing.Process(target=worker) | |
jobs.append(p) | |
p.start() | |
while True: | |
linktext = raw_input("Click link:") | |
if not linktext: | |
writevalue('QUIT') | |
time.sleep(5) | |
break | |
writevalue(linktext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment