def _get_Firefox(self):
try:
if self.proxy:
profile = webdriver.FirefoxProfile()
profile.set_preference(
"network.proxy.type",
1
) # this means that the proxy is user set
if self.proxy.proto.lower().startswith('socks'):
profile.set_preference(
"network.proxy.socks",
self.proxy.host
)
profile.set_preference(
"network.proxy.socks_port",
self.proxy.port
)
profile.set_preference(
"network.proxy.socks_version",
5 if self.proxy.proto[-1] == '5' else 4
)
profile.update_preferences()
elif self.proxy.proto == 'http':
profile.set_preference(
"network.proxy.http",
self.proxy.host
)
profile.set_preference(
"network.proxy.http_port",
self.proxy.port
)
else:
raise ValueError('Invalid protocol given in proxyfile.')
profile.update_preferences()
self.webdriver = webdriver.Firefox(firefox_profile=profile)
else:
self.webdriver = webdriver.Firefox()
return True
except WebDriverException as e:
# no available webdriver instance.
logger.error(e)
return False
评论列表
文章目录