我使用selenium和多处理来生成四个不同的网站,我想运行特定于驱动程序生成的网站的功能。
这与我目前的代码类似:
from multiprocessing import Pool
from selenium import webdriver
def gh(hosts):
driver = webdriver.Chrome(executable_path='./chromedriver')
driver.get(hosts)
html_source = driver.page_source
if 'ryan' in html_source:
print 'ryan'
doSomethingForRyan()
elif 'austin' in html_source:
print 'austin'
doSomethingForAustin()
elif 'travis' in html_source:
print 'travis'
doSomethingForTravis()
elif 'levi' in html_source:
print 'levi'
doSomethingForLevi()
else:
print '--NONE--'
if __name__ == '__main__':
p = Pool(4)
hosts = ["http://ryan.com", "https://www.austin.com", "http://levi.com", "http://travis.com"]
p.map(gh, hosts)
我得到的结果如下: 奥斯汀 奥斯汀 瑞安 奥斯汀
答案 0 :(得分:0)
编辑 - 已解决
不是从driver.page_source读取,而是从driver.current_url读取,以确保我可以运行特定于网站的功能。
if 'ryan' in driver.current_url:
print 'ryan'
doStuff()