selenium.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:SerpScrap 作者: ecoron 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号