首页 > 编程语言 >python库多版本共存

python库多版本共存

时间:2023-10-09 17:38:30浏览次数:37  
标签:库多 webdriver python selenium driver sys 共存 import options

安装多版本selenium

在 Python 中处理包的多个版本 |作者:跳过 |中等 (medium.com)

如何在一个python 文件用两个不同版本的库_python 有两个库,怎么在代码中选择用哪个库-CSDN博客

安装3.14.0版本
pip install selenium==3.14.0 --target=C:\selenium\3.14.0
安装 4.12.0版本
pip install selenium==4.12.0 --target=C:\selenium\4.12.0

测试脚本

# -*- coding: UTF-8 -*-
import os
import sys
import time

selenium_version = 3

if selenium_version == 3:
    sys.path.insert(1, os.path.abspath(r'C:\selenium\3.14.0'))
    import selenium
    print(selenium.__version__)

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service as ChromeService
    from webdriver_manager.chrome import ChromeDriverManager

    options = webdriver.ChromeOptions()
    options.add_argument("--ignore-certificate-error")
    options.add_argument("--ignore-ssl-errors")
    driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
    driver.maximize_window()

    driver.get("https://www.baidu.com/")
    driver.find_element_by_id('kw').send_keys('python')
    driver.find_element_by_id('su').click()

    time.sleep(2)
    driver.quit()

    # print(sys.path)
    # for key in list(sys.modules.keys()):
    #     if key.startswith('selenium'):
    #         del sys.modules[key]
elif selenium_version == 4:
    sys.path.insert(1, os.path.abspath(r'C:\selenium\4.12.0'))
    import selenium
    print(selenium.__version__)

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service as ChromeService
    from webdriver_manager.chrome import ChromeDriverManager
    from selenium.webdriver.common.by import By

    options = webdriver.ChromeOptions()
    options.add_argument("--ignore-certificate-error")
    options.add_argument("--ignore-ssl-errors")
    driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options=options)
    driver.maximize_window()

    driver.get("https://www.baidu.com/")
    driver.find_element(By.ID, 'kw').send_keys('python')
    driver.find_element(By.ID, 'su').click()

    time.sleep(2)
    driver.quit()
    # print(sys.path)

 

标签:库多,webdriver,python,selenium,driver,sys,共存,import,options
From: https://www.cnblogs.com/daizichuan/p/17752250.html

相关文章

  • python 字典嵌套(列表及字典)取值/统计方案
    classDictionaryProcessingSet:result_dict={}defget_key(self,data:dict,demand:list,countKey:str=''):""":paramdata:入参数据:paramdemand:你的需求参数:paramcountKey:参数统计次数......
  • Python 时间_Datetime_Module
    Datetime_Module作用:处理日期和时间一、Datetime模块中的类datetime:表示日期和时间,可以处理年、月、日、时、分、秒。date:表示日期,主要用于处理年、月、日。time:表示时间,主要用于处理时、分、秒。timedelta:表示时间间隔,即两个时间点的间隔,主要用于做时间加减。tzinfo:时区......
  • python如何配置文件路径
    1、获取被调用函数所在的模块文件名,然后获取其路径。2、与配置文件所在的路径进行比较,基于模块文件路径和父级路径的配置文件所在的相对路径,获得配置文件的绝对路径。co_filepath=sys._getframe().f_code.co_filenamehead,tail=os.path.split(co_filepath)conf_filepa......
  • Python生成随机整数数组的实用方法
    在编程中,生成随机整数数组是一项非常常见的任务。本文将介绍如何使用Python语言来生成随机整数数组,帮助读者掌握这一有用的编程技巧。通过实际的代码示例,我们将逐步指导读者完成生成随机整数数组的过程,并提供一些实际应用的建议。第一部分:了解随机数生成原理1.什么是随机数:-随机数......
  • Python_滑动窗口
    SQL中窗口函数常用窗口函数窗口函数主要分为了聚合、排序、分布、平移及首尾等类型1)聚合函数:sum()、count()、max()、min()、avg()2)排序函数:row_number()、rank()、dense_rank()3)分布函数:percent_rank()、cume_dist()4)平移函数:lead()、lag()5)首尾函数......
  • 7、Python语法入门之流程控制
    7、Python语法入门之流程控制转载: 7、Python语法入门之流程控制-知乎(zhihu.com)目录:引子分支结构什么是分支结构为什么要用分支结构如何使用分支结构if语法if应用案例循环结构什么是循环结构为什么要用循环结构如何使用循环结构while循环语......
  • 几个易错的python小知识点
    大家好,我是暴走の海鸽~本期整理了几个基础python防坑小常识,希望对大家有所帮助。1.type==object?执行以下代码的结果是什么:>>>isinstance(type,object)True>>>isinstance(object,type)True>>>isinstance(object,object)True>>>isinstance(type,type)True......
  • 笨办法学Python3 习题30 else 和 if
    1people=302cars=403trucks=1545ifcars>people:#下面同时为True,也只会运行第一个为True的块,另外两个优先级依次低于if6print("Weshouldtakethecars.")#第一个分支的块78elifcars<people:......
  • 笨办法学Python3 习题29 if 语句
    1people=202cats=303dogs=1545ifpeople<cats:6print("Toomanycats!Theworldisdoomed!")78ifpeople>cats:9print("Notmanycats!Theworldissaved!")1011ifpeople<dogs:12p......
  • Command "python setup.py egg_info" failed with error code 1
     D:\ProgramFiles\python_3_6_4>python-mpipinstall--upgradepipCacheentrydeserializationfailed,entryignoredCollectingpip Cacheentrydeserializationfailed,entryignored Downloadinghttps://files.pythonhosted.org/packages/a4/6d/6463d49a93......