亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
在Selenium中設(shè)置代理IP
作者:丁于 發(fā)布時間:[ 2017/3/28 11:34:31 ] 推薦標(biāo)簽:功能測試 Selenium

  Firefox中設(shè)置代理ip
  method_1
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.http', '127.0.0.1')
profile.set_preference('network.proxy.http_port', 17890)  # int
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('http://httpbin.org/ip')
  method_2
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
proxy = Proxy(
{
# 'proxyType': ProxyType.MANUAL,  # 用不用都行
'httpProxy': get_proxy_ip_port()
}
)
driver = webdriver.Firefox(proxy=proxy)
driver.get('http://httpbin.org/ip')
  phantomjs中設(shè)置代理ip
  方法一:太不優(yōu)雅(還是看方法二吧)
  在phantomjs中不能像上面的Firefox的method2一樣傳入proxy
  phantomjs和Firefox均繼承自WebDriver,父類WebDriver可以傳入proxy
  phantomjs在初始化WebDriver時沒有留proxy參數(shù)
  所以可以像下圖一樣改一下phantomjs類的源碼,可以在phantomjs中傳入proxy參數(shù)了
# 注意授權(quán)
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

  下面才是示例
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': get_proxy_ip_port()
}
)
driver = webdriver.PhantomJS(
executable_path="/path/of/phantomjs",
proxy=proxy
)
driver.get('http://httpbin.org/ip')
print driver.page_source
driver.close()
  方法二:
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': 'ip:port'  # 代理ip和端口
}
)
# 新建一個“期望技能”,哈哈
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
# 把代理ip加入到技能中
proxy.add_to_capabilities(desired_capabilities)
driver = webdriver.PhantomJS(
executable_path="/path/of/phantomjs",
desired_capabilities=desired_capabilities
)
driver.get('http://httpbin.org/ip')
print driver.page_source
driver.close()
  方法三(動態(tài)切換ip):
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy
from selenium.webdriver.common.proxy import ProxyType
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': 'ip:port'  # 代理ip和端口
}
)
# 新建一個“期望技能”,哈哈
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
# 把代理ip加入到技能中
proxy.add_to_capabilities(desired_capabilities)
driver = webdriver.PhantomJS(
executable_path="/path/of/phantomjs",
desired_capabilities=desired_capabilities
)
# 測試一下
driver.get('http://httpbin.org/ip')
print driver.page_source
# 現(xiàn)在開始切換ip
# 再新建一個ip
proxy = Proxy(
{
'proxyType': ProxyType.MANUAL,
'httpProxy': 'ip:port'  # 代理ip和端口
}
)
# 再新建一個“期望技能”,()
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
# 把代理ip加入到技能中
proxy.add_to_capabilities(desired_capabilities)
# 新建一個會話,并把技能傳入
driver.start_session(desired_capabilities)
driver.get('http://httpbin.org/ip')
print driver.page_source
driver.close()

軟件測試工具 | 聯(lián)系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 国产好片无限资源 | 伊人手机在线视频 | 亚洲欧洲日韩在线 | 欧美成人性色生活片免费在线观看 | 99在线观看视频免费精品9 | 久久精品亚洲精品国产欧美 | 午夜影视体验区 | 亚洲伊人久久综合一区二区 | 男女羞羞视频免费看 | 又黄又爽一线毛片免费观看 | 免费黄色网址在线播放 | 无遮羞无删减肉动漫在线观看 | 久久免费精品高清麻豆 | 国产精品视频免费一区二区三区 | 午夜 在线 | 国产三级国产精品 | 免费二级c片在线观看a | 一级做a爰片久久毛片看看 一级做a爰久久毛片武则天 | 天天天色 | 久久99国产这里有精品视 | 麻豆轻量版 | 色99在线| 色综合狠狠操 | 国内精品免费视频自在线 | 香港一级a毛片在线播放 | 日韩黄色精品 | 色停停 | 91视频 88av | 国产黄大片在线观看视频 | 国产精品久久久久久亚洲伦理 | 精品国产免费观看一区高清 | 国产裸舞在线一区二区 | 波多野结衣在线观看3人 | 黄色网址免费大全 | 天堂在线观看视频观看www | 在线观看福利影院 | 一级在线 | 欧洲 | 日本护士xxxxx18.19 | 茄子视频黄 | 日本欧美一区 | 最新午夜 |