zoukankan      html  css  js  c++  java
  • 浏览器模拟手机模式操作

    代码实现如下:

    import os
    from  selenium import webdriver
    
    #配置浏览器以手机模式启动
    chrome_options = webdriver.ChromeOptions()
    #选择一种存在的模式手机设备(分辨率)
    chrome_options.add_experimental_option('mobileEmulation',{'deviceName':'iPhone X'})
    print(type(chrome_options)) #import os
    from  selenium import webdriver
    
    #配置浏览器以手机模式启动
    chrome_options = webdriver.ChromeOptions()
    #选择一种存在的模式手机设备(分辨率)
    chrome_options.add_experimental_option('mobileEmulation',{'deviceName':'iPhone X'})
    print(type(chrome_options)) #<class 'selenium.webdriver.chrome.options.Options'>
    print(chrome_options.to_capabilities()) #{'browserName': 'chrome', 'version': '', 'platform': 'ANY', 'goog:chromeOptions': {'mobileEmulation': {'deviceName': 'iPhone X'}, 'extensions': [], 'args': []}}
    #将chrome_options:创建一个包含所有已设置选项和返回包含所有内容的词典
    new_new_chrome_options = chrome_options.to_capabilities()
    path= os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    executable_path = f'{path}/driver/chromedriver.exe'
    #创建一个driver
    driver = webdriver.Chrome(executable_path=executable_path,desired_capabilities=new_new_chrome_options)
    driver.get('http://www.baidu.com')
    driver.find_element_by_id('index-kw').send_keys('李白
    ')
    driver.quit()
    print(chrome_options.to_capabilities())
    #将chrome_options:创建一个包含所有已设置选项和返回包含所有内容的词典
    new_new_chrome_options = chrome_options.to_capabilities()
    path= os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    executable_path = f'{path}/driver/chromedriver.exe'
    #创建一个driver
    driver = webdriver.Chrome(executable_path=executable_path,desired_capabilities=new_new_chrome_options)
    driver.get('http://www.baidu.com')
    driver.find_element_by_id('index-kw').send_keys('李白
    ')
    driver.quit()
  • 相关阅读:
    关于Windows 2000,IIS 5/4下面,Form内容超过200K解决办法!
    获取客户端网卡MAC地址和IP地址的几种方法
    关于Java的异常捕获
    redis的swap
    Linux下C++程序获取运行时间的一种方式
    CentOS 修改IP地址, DNS, 网关[内容来源网络]
    [转]ubuntu12.04搭建ruby on rails 环境
    rails环境 bundle 时无法安装nokogiri 完美解决
    SQL Server – 冷知识 (新手)
    Typescript – 学习笔记 tsconfig.json
  • 原文地址:https://www.cnblogs.com/zhuxibo/p/14266540.html
Copyright © 2011-2022 走看看