selenium控制浏览器为手机模式

# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep


mobileEmulation = {'deviceName': 'Apple iPhone 4'}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)

driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=options)

driver.get('http://m.baidu.com')

sleep(3)
driver.close()

  其中Apple iPhone 4为浏览器内支持的手机型号

posted @ 2017-11-29 16:59  xqnq2007  阅读(3272)  评论(0编辑  收藏  举报