1. Configure related drivers
Chrome Driver
Download driver, configure to environment variable
such as Xxxxchrome.jar to create a new directory c:/driver---Configure the directory to an environment variable
Firefox driver
Download the driver, unzip the Geckodriver-v0.21.0-win64.zip, drag the Geckodriver-v0.21.0-win64 to the Python--script directory
IE driver
Download the driver and IEDriverServer.exe it to C:\Windows\System32
2. Code
From selenium import Webdriver
From threading Import Thread
Import Threading,time
From time import CTime
def test_baidu (Browser,search):
Print (' start:%s '% CTime ())
Print (' broswer:%s '%browser)
If browser== ' IE ':
Driver=webdriver. Ie ()
Print (' IE search results ')
Elif browser== ' Chrome ':
Driver=webdriver. Chrome ()
Print (' Google search results ')
elif browser== ' FF ':
Driver=webdriver. Firefox ()
Print (' Firefox search results ')
Else
Print (' browser error ')
Driver.get (' http://www.baidu.com ')
driver.find_element_by_id (' kw '). Send_keys (search)
driver.find_element_by_id (' su '). Click ()
Time.sleep (1)
Driver.quit ()
If __name__== ' __main__ ':
#指定浏览器搜索内容
lists={' Chrome ': ' Threading ', ' IE ': ' Start ', ' ff ': ' Fight '}
Threads=[]
Files=range (len (lists))
#创建线程
For Browser,search in Lists.items ():
T=thread (target=test_baidu,args= (Browser,search))
Threads.append (t)
#启动线程
For T in Files:
Threads[t].start ()
For T in Files:
Threads[t].join ()
Print (' End%s '%ctime ())
Selenum Threding Multithreaded Running instance