zoukankan      html  css  js  c++  java
  • selenium启动chrome模拟器模拟手机

    一、如果chrome选项里边有这个模拟设备(比如iPhone 6 Plus):

    1、先启动Selenium Grid, 比如命令:java -jar selenium-server-standalone-XXX.jar。

    2、代码如下:

    #coding=utf-8
    from selenium import webdriver
    
    mobile_emulation = { "deviceName": "iPhone 6 Plus" }
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
    driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',
                              desired_capabilities = chrome_options.to_capabilities())

    二、如果chrome选项里边没有预置这个模拟设备,也可以自己配置,代码如下:

    #coding=utf-8
    from selenium import webdriver
    
    mobile_emulation = {
        "deviceMetrics": { "width": 414, "height": 736, "pixelRatio": 3.0 },
        "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1" }
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
    driver = webdriver.Chrome(chrome_options = chrome_options)

    三、修改浏览器的User-Agent来伪装你的浏览器访问手机m站,代码如下:

    #coding=utf-8
    from selenium import webdriver
    
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--user-agent=
    Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1')
    driver
    = webdriver.Chrome(chrome_options = chrome_options)
  • 相关阅读:
    OpenStack--Rabbitmq组件消息队列
    Redis-主从
    haproxy mycat mysql 读写分离MHA高可用
    mysql小白系列_14 线上故障分析与排错
    mysql小白系列_13 Online DDL
    mysql小白系列_12 sysbench
    mysql小白系列_11 MHA补充
    mysql小白系列_11 MHA
    mysql小白系列_10 mysql主从复制原理
    mysql小白系列_09 mysql性能优化关键点
  • 原文地址:https://www.cnblogs.com/xmlbw/p/5659698.html
Copyright © 2011-2022 走看看