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

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

  Firefox中設置代理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中設置代理ip
  方法一:太不優雅(還是看方法二吧)
  在phantomjs中不能像上面的Firefox的method2一樣傳入proxy
  phantomjs和Firefox均繼承自WebDriver,父類WebDriver可以傳入proxy
  phantomjs在初始化WebDriver時沒有留proxy參數
  所以可以像下圖一樣改一下phantomjs類的源碼,可以在phantomjs中傳入proxy參數了
# 注意授權
# 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()
  方法三(動態切換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
# 現在開始切換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()

軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 欧美最猛性xxxxxhd | 一及毛片 | 羞羞免费网站 | 中文字幕免费在线观看 | 动漫美女胸被狂揉扒开吃奶动态图 | 欧美黄色免费网站 | 免费一级特黄a | 小黄漫画激情四射在线观看 | 欧美在线看片a免费观看 | 欧美一级网站 | 首页 国产 日韩 欧美 动漫 | 国美女福利视频午夜精品 | 在线观看你懂的视频 | 波多野结衣免费一区二区三区香蕉 | 五月婷婷在线观看 | 你懂得在线视频 | 最近2019好看的中文字幕免费 | 成人性色大片 | 高清不卡日本v在线二区 | 国产草逼视频 | 黄色影院免费看 | 欧美成人做性视频在线播放 | 亚洲图片欧美文学小说激情 | 欧美性xxx极品hd高清 | 你懂的在线视频播放 | 午夜视频在线观看国产www | 最近中文字幕2019国语7 | 久久精品一级 | 一级片中文字幕 | 97视频精品全国在线观看 | 日韩免费视频播放 | 香蕉在线视频网站 | 亚洲aaaa级特黄毛片 | 一个人看的视频www在线看 | 亚洲国产经典 | 高清黄色一级片 | 国产一区二区三区免费 | 亚洲午夜一区 | 香蕉视频污污在线观看 | 亚洲国产中文字幕 | 成人午夜性a一级毛片美女 成人午夜小视频 |