本文整理汇总了Python中selenium.webdriver.common.proxy.Proxy类的典型用法代码示例。如果您正苦于以下问题:Python Proxy类的具体用法?Python Proxy怎么用?Python Proxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Proxy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: tt1
def tt1():
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Host': 'www.dianping.com',
}
for key, value in headers.iteritems():
desired_capabilities['phantomjs.page.customHeaders.{}'.format(key)] = value
desired_capabilities[
'phantomjs.page.customHeaders.User-Agent'] = \
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) ' \
'AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 ' \
'Safari/604.1.38'
ip_port = random.choice(redis_conn1())
print ip_port
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': '%s' % ip_port # 代理ip和端口
}
)
proxy.add_to_capabilities(desired_capabilities)
print desired_capabilities
driver = webdriver.PhantomJS(desired_capabilities=desired_capabilities)
driver.set_page_load_timeout(10)
driver.get("http://www.dianping.com/shop/%s" % ['76964345', '15855144', ])
list1 = driver.find_elements_by_xpath('//div[@class="comment-condition J-comment-condition Fix"]/div/span/a')
for l in list1:
print l.text
if '403 Forbidden' in driver.page_source:
print driver.page_source
driver.close()
开发者ID:qingfengliu,项目名称:python_study,代码行数:35,代码来源:dianping_phantomjs.py
示例2: getDriver
def getDriver(self, driverType='firefox'):
try:
if driverType == 'phantomjs':
#capabilities = webdriver.DesiredCapabilities.PHANTOMJS.copy()
#capabilities['platform'] = "LINUX"
driver = webdriver.PhantomJS('/usr/local/share/phantomjs/bin/phantomjs')
else:
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
self.dis = Display(visible=0,size=(800,600))
self.dis.start()
prx = Proxy()
prx.httpProxy= '199.200.120.36:8089' #'112.196.3.254:9064' india
prx.proxyType = ProxyType.MANUAL
prof = FirefoxProfile('./ffprofile')
driver = webdriver.Firefox(proxy=prx, firefox_profile=prof)
driver.implicitly_wait(30)
driver.set_page_load_timeout(30)
print 'started the driver successfully...'
return driver
except Exception as e:
print 'error has occured while starting the driver....'
print type(e)
print e
self.quit()
#sys.exit(0)
return None
开发者ID:ayat-ra,项目名称:lnkdinBrowser,代码行数:26,代码来源:lnkdin_browser.py
示例3: testCanNotChangeInitializedProxyType
def testCanNotChangeInitializedProxyType(self):
proxy = Proxy(raw={'proxyType': 'direct'})
try:
proxy.proxy_type = ProxyType.SYSTEM
raise Exception("Change of already initialized proxy type should raise exception")
except Exception as e:
pass
开发者ID:TheBits,项目名称:selenium-webdriver-python,代码行数:7,代码来源:proxy_tests.py
示例4: test_autodetect_proxy_is_set_in_profile
def test_autodetect_proxy_is_set_in_profile():
profile = FirefoxProfile()
proxy = Proxy()
proxy.auto_detect = True
profile.set_proxy(proxy)
assert profile.default_preferences["network.proxy.type"] == ProxyType.AUTODETECT['ff_value']
开发者ID:Allariya,项目名称:selenium,代码行数:7,代码来源:ff_profile_tests.py
示例5: testCanNotChangeInitializedProxyType
def testCanNotChangeInitializedProxyType():
proxy = Proxy(raw={'proxyType': 'direct'})
with pytest.raises(Exception):
proxy.proxy_type = ProxyType.SYSTEM
proxy = Proxy(raw={'proxyType': ProxyType.DIRECT})
with pytest.raises(Exception):
proxy.proxy_type = ProxyType.SYSTEM
开发者ID:Allariya,项目名称:selenium,代码行数:8,代码来源:proxy_tests.py
示例6: test_pac_proxy_is_set_in_profile
def test_pac_proxy_is_set_in_profile():
profile = FirefoxProfile()
proxy = Proxy()
proxy.proxy_autoconfig_url = 'http://some.url:12345/path'
profile.set_proxy(proxy)
assert profile.default_preferences["network.proxy.type"] == ProxyType.PAC['ff_value']
assert profile.default_preferences["network.proxy.autoconfig_url"] == 'http://some.url:12345/path'
开发者ID:Allariya,项目名称:selenium,代码行数:8,代码来源:ff_profile_tests.py
示例7: test_what_things_look_like
def test_what_things_look_like(self):
bmp_capabilities = copy.deepcopy(selenium.webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX)
self.client.add_to_capabilities(bmp_capabilities)
proxy_capabilities = copy.deepcopy(selenium.webdriver.common.desired_capabilities.DesiredCapabilities.FIREFOX)
proxy = Proxy({'httpProxy': 'localhost:%d' % self.client.port})
proxy.add_to_capabilities(proxy_capabilities)
assert bmp_capabilities == proxy_capabilities
开发者ID:Inetgate,项目名称:browsermob-proxy-py,代码行数:9,代码来源:test_webdriver.py
示例8: test_sets_ssl_proxy
def test_sets_ssl_proxy(self):
self.driver.quit()
profile = webdriver.FirefoxProfile()
proxy = Proxy()
proxy.ssl_proxy = 'https://test.hostname:1234'
profile.set_proxy(proxy)
assert profile.default_preferences["network.proxy.type"] == str(ProxyType.MANUAL['ff_value'])
assert profile.default_preferences["network.proxy.ssl"] == '"test.hostname"'
assert profile.default_preferences["network.proxy.ssl_port"] == '1234'
开发者ID:AlexandraChiorean,项目名称:Selenium2,代码行数:10,代码来源:ff_profile_tests.py
示例9: testCanAddPACProxyToDesiredCapabilities
def testCanAddPACProxyToDesiredCapabilities():
proxy = Proxy()
proxy.proxy_autoconfig_url = PAC_PROXY['proxyAutoconfigUrl']
desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
proxy_capabilities = PAC_PROXY.copy()
proxy_capabilities['proxyType'] = 'PAC'
expected_capabilities = {'proxy': proxy_capabilities}
assert expected_capabilities == desired_capabilities
开发者ID:Allariya,项目名称:selenium,代码行数:11,代码来源:proxy_tests.py
示例10: testCanAddAutodetectProxyToDesiredCapabilities
def testCanAddAutodetectProxyToDesiredCapabilities():
proxy = Proxy()
proxy.auto_detect = AUTODETECT_PROXY['autodetect']
desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
proxy_capabilities = AUTODETECT_PROXY.copy()
proxy_capabilities['proxyType'] = 'AUTODETECT'
expected_capabilities = {'proxy': proxy_capabilities}
assert expected_capabilities == desired_capabilities
开发者ID:Allariya,项目名称:selenium,代码行数:11,代码来源:proxy_tests.py
示例11: testCanAddPACProxyToDesiredCapabilities
def testCanAddPACProxyToDesiredCapabilities(self):
proxy = Proxy()
proxy.proxy_autoconfig_url = self.PAC_PROXY['proxyAutoconfigUrl']
desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
proxy_capabilities = self.PAC_PROXY.copy()
proxy_capabilities['proxyType'] = 'PAC'
expected_capabilities = {'proxy': proxy_capabilities}
self.assertEqual(expected_capabilities, desired_capabilities)
开发者ID:217,项目名称:selenium,代码行数:11,代码来源:proxy_tests.py
示例12: testCanAddAutodetectProxyToDesiredCapabilities
def testCanAddAutodetectProxyToDesiredCapabilities(self):
proxy = Proxy()
proxy.auto_detect = self.AUTODETECT_PROXY['autodetect']
desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
proxy_capabilities = self.AUTODETECT_PROXY.copy()
proxy_capabilities['proxyType'] = 'AUTODETECT'
expected_capabilities = {'proxy': proxy_capabilities}
self.assertEqual(expected_capabilities, desired_capabilities)
开发者ID:217,项目名称:selenium,代码行数:11,代码来源:proxy_tests.py
示例13: test_autodetect_proxy_is_set_in_profile
def test_autodetect_proxy_is_set_in_profile(self):
# The setup gave us a browser but we dont need it
self.driver.quit()
self.profile = webdriver.FirefoxProfile()
proxy = Proxy()
proxy.auto_detect = True
self.profile.set_proxy(proxy)
assert self.profile.default_preferences["network.proxy.type"] == ProxyType.AUTODETECT['ff_value']
开发者ID:217,项目名称:selenium,代码行数:11,代码来源:ff_profile_tests.py
示例14: test_pac_proxy_is_set_in_profile
def test_pac_proxy_is_set_in_profile(self):
# The setup gave us a browser but we dont need it
self.driver.quit()
self.profile = webdriver.FirefoxProfile()
proxy = Proxy()
proxy.proxy_autoconfig_url = 'http://some.url:12345/path'
self.profile.set_proxy(proxy)
assert self.profile.default_preferences["network.proxy.type"] == ProxyType.PAC['ff_value']
assert self.profile.default_preferences["network.proxy.autoconfig_url"] == 'http://some.url:12345/path'
开发者ID:217,项目名称:selenium,代码行数:12,代码来源:ff_profile_tests.py
示例15: testCanNotChangeInitializedProxyType
def testCanNotChangeInitializedProxyType(self):
proxy = Proxy(raw={"proxyType": "direct"})
try:
proxy.proxy_type = ProxyType.SYSTEM
raise Exception("Change of already initialized proxy type should raise exception")
except Exception:
pass
proxy = Proxy(raw={"proxyType": ProxyType.DIRECT})
try:
proxy.proxy_type = ProxyType.SYSTEM
raise Exception("Change of already initialized proxy type should raise exception")
except Exception:
pass
开发者ID:RanchoLi,项目名称:selenium,代码行数:14,代码来源:proxy_tests.py
示例16: test_manual_proxy_is_set_in_profile
def test_manual_proxy_is_set_in_profile():
profile = FirefoxProfile()
proxy = Proxy()
proxy.no_proxy = 'localhost, foo.localhost'
proxy.http_proxy = 'some.url:1234'
proxy.ftp_proxy = None
proxy.sslProxy = 'some2.url'
profile.set_proxy(proxy)
assert profile.default_preferences["network.proxy.type"] == ProxyType.MANUAL['ff_value']
assert profile.default_preferences["network.proxy.no_proxies_on"] == 'localhost, foo.localhost'
assert profile.default_preferences["network.proxy.http"] == 'some.url'
assert profile.default_preferences["network.proxy.http_port"] == 1234
assert profile.default_preferences["network.proxy.ssl"] == 'some2.url'
assert "network.proxy.ssl_port" not in profile.default_preferences
assert "network.proxy.ftp" not in profile.default_preferences
开发者ID:Allariya,项目名称:selenium,代码行数:16,代码来源:ff_profile_tests.py
示例17: __init__
def __init__(self, host="127.0.0.1", server="./selenium-server.jar"):
if server and path.isfile(server) and not _server_started():
self.selenium = _Selenium(server)
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': host,
'ftpProxy': host,
'sslProxy': host,
'noProxy': host
})
caps = webdriver.DesiredCapabilities.FIREFOX
proxy.add_to_capabilities(caps)
try:
self.driver = webdriver.Remote(desired_capabilities=caps)
except URLError:
raise SeleniumServerError
开发者ID:jsimnz,项目名称:selenate,代码行数:17,代码来源:selenate.py
示例18: testCanAddManualProxyToDesiredCapabilities
def testCanAddManualProxyToDesiredCapabilities(self):
proxy = Proxy()
proxy.http_proxy = self.MANUAL_PROXY["httpProxy"]
proxy.ftp_proxy = self.MANUAL_PROXY["ftpProxy"]
proxy.no_proxy = self.MANUAL_PROXY["noProxy"]
proxy.sslProxy = self.MANUAL_PROXY["sslProxy"]
proxy.socksProxy = self.MANUAL_PROXY["socksProxy"]
proxy.socksUsername = self.MANUAL_PROXY["socksUsername"]
proxy.socksPassword = self.MANUAL_PROXY["socksPassword"]
desired_capabilities = {}
proxy.add_to_capabilities(desired_capabilities)
proxy_capabilities = self.MANUAL_PROXY.copy()
proxy_capabilities["proxyType"] = "MANUAL"
expected_capabilities = {"proxy": proxy_capabilities}
self.assertEqual(expected_capabilities, desired_capabilities)
开发者ID:RanchoLi,项目名称:selenium,代码行数:17,代码来源:proxy_tests.py
示例19: __init__
def __init__(self, host="127.0.0.1", server="./selenium-server.jar"):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
port = sock.connect_ex(("127.0.0.1", 4444)) == 0
if server and path.isfile(server) and not port:
self.selenium = _Selenium(server)
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': host,
'ftpProxy': host,
'sslProxy': host,
'noProxy': host
})
caps = webdriver.DesiredCapabilities.FIREFOX
proxy.add_to_capabilities(caps)
try:
self.driver = webdriver.Remote(desired_capabilities=caps)
except URLError:
raise SeleniumServerError
开发者ID:dkua,项目名称:selenate,代码行数:19,代码来源:selenate.py
示例20: test_manual_proxy_is_set_in_profile
def test_manual_proxy_is_set_in_profile(self):
# The setup gave us a browser but we dont need it
self.driver.quit()
self.profile = webdriver.FirefoxProfile()
proxy = Proxy()
proxy.no_proxy = 'localhost, foo.localhost'
proxy.http_proxy = 'some.url:1234'
proxy.ftp_proxy = None
proxy.sslProxy = 'some2.url'
self.profile.set_proxy(proxy)
assert self.profile.default_preferences["network.proxy.type"] == ProxyType.MANUAL['ff_value']
assert self.profile.default_preferences["network.proxy.no_proxies_on"] == 'localhost, foo.localhost'
assert self.profile.default_preferences["network.proxy.http"] == 'some.url'
assert self.profile.default_preferences["network.proxy.http_port"] == 1234
assert self.profile.default_preferences["network.proxy.ssl"] == 'some2.url'
assert "network.proxy.ssl_port" not in self.profile.default_preferences
assert "network.proxy.ftp" not in self.profile.default_preferences
开发者ID:217,项目名称:selenium,代码行数:20,代码来源:ff_profile_tests.py
注:本文中的selenium.webdriver.common.proxy.Proxy类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论