环保行业网站建设,百度惠生活小程序,专做国外旅游的网站,怎么封锁网站文章目录 修改安装源打开Python Packages。点击梅花按钮。在弹出的对话框中#xff0c;填入Name#xff08;随便填#xff09;#xff0c;Repository URL#xff0c;选择下列的源#xff0c;一般先选择清华源按OK确认。配置完成 安装seleniumFile→Settings→Project填入Name随便填Repository URL选择下列的源一般先选择清华源按OK确认。配置完成 安装seleniumFile→Settings→ProjectSTEST1→Python Interperter→点“”→在新框中输入selenium。在下面搜索出来的一些列结果中选择selenium注意可能有多个selenium选择你想要的URL路径这里我们选择的是清华源的路径看图示。按Install Package慢慢等待安装成功。 安装浏览器驱动-Chrome安装Chrome浏览器。https://www.google.cn/chrome/index.html去官网下载最新版本。下载对应的驱动进入下载文件夹根据自己的需要下载对应版本的驱动。配置环境变量测试Chrome打开Pycharm新建main.py,按如下输入 press the green button in the gutter to run the script记录问题解决执行最后生效 安装浏览器驱动-Firefox安装Firefox浏览器。https://www.firefox.com.cn/下载对应的驱动 测试Firefox 在Firefox中安装Selenium IDE点击进入选择添加到Firefox勾选允许此扩展在隐私窗口中运行。可以不勾选但目前不清楚会产生什么问题还是勾选此时在Firefox右上角出现Selenium IDE图标。 修改安装源
打开Python Packages。
点击梅花按钮。
在弹出的对话框中填入Name随便填Repository URL选择下列的源一般先选择清华源
国内源列表一般是清华源比较好 阿里云http://mirrors.aliyun.com/pypi/simple/ 豆瓣http://pypi.douban.com/simple/ 清华大学https://pypi.tuna.tsinghua.edu.cn/simple/ 中国科学技术大学https://pypi.mirrors.ustc.edu.cn/simple/ 本来的源https://pypi.org/simple
按OK确认。 配置完成 安装selenium
File→Settings→ProjectSTEST1→Python Interperter→点“”→在新框中输入selenium。
在下面搜索出来的一些列结果中选择selenium注意可能有多个selenium选择你想要的URL路径这里我们选择的是清华源的路径看图示。
按Install Package慢慢等待安装成功。 安装浏览器驱动-Chrome
安装Chrome浏览器。https://www.google.cn/chrome/index.html去官网下载最新版本。
按照一下步骤查看版本号
下载对应的驱动
网址https://googlechromelabs.github.io/chrome-for-testing/。 选择与版本号最接近的驱动下载。
复制下载链接到浏览器上触发下载 https://storage.googleapis.com/chrome-for-testing-public/130.0.6723.58/win64/chrome-headless-shell-win64.zip
进入下载文件夹根据自己的需要下载对应版本的驱动。
解压下载的文件。 将chromedriver.exe拷贝至Chrome所在文件夹C:\Program Files\Google\Chrome\Application。注意可能在Program FilesX86文件夹。 设置环境变量 在系统搜索框中输入“环境变量”打开编辑系统环境变量界面按照以下步骤在系统环境变量的Path项目里添加chromedriver.exe所在目录。
拷贝到文件目录上方C:\Program Files\Google\Chrome\Application 将下载的文件拷贝 配置环境变量 测试Chrome
打开Pycharm新建main.py,按如下输入
from selenium import webdriver
import timedef test():driver webdriver.Chrome()driver.get(https://www.shou.org.cn/)time.sleep(2)driver.quit()press the green button in the gutter to run the script
if name ‘main’: test() 正常效果打开开大页面2s后自动关闭。 若出现如下错误则由于Pycharm未更新上一步设置的环境变量所造成。关闭Pycharm后再重新打开即可。
记录问题
Traceback (most recent call last): File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest\env-selenium\main.py”, line 1, in from selenium import webdriver File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest.venv\lib\site-packages\selenium\webdriver_init_.py”, line 20, in from .chrome.webdriver import WebDriver as Chrome # noqa File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest.venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py”, line 18, in from selenium.webdriver.chromium.webdriver import ChromiumDriver File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest.venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py”, line 18, in from selenium.webdriver.chromium.remote_connection import ChromiumRemoteConnection File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest.venv\lib\site-packages\selenium\webdriver\chromium\remote_connection.py”, line 18, in from selenium.webdriver.remote.remote_connection import RemoteConnection File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest.venv\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 27, in import urllib3 File “E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest.venv\lib\site-packages\urllib3_init_.py”, line 42, in urllib3 v2.0 only supports OpenSSL 1.1.1, currently ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1, currently the ‘ssl’ module is compiled with ‘OpenSSL 1.1.0h 27 Mar 2018’. See: https://github.com/urllib3/urllib3/issues/2168
Process finished with exit code 1
解决
这个错误信息表明你的Python环境中安装的urllib3库版本2.0需要OpenSSL 1.1.1或更高版本但是当前Python的ssl模块是使用OpenSSL 1.1.0h版本编译的。这导致了不兼容的问题。
要解决这个问题你可以采取以下几种方法之一
升级OpenSSL 如果你有权限和能力在你的系统上升级OpenSSL库并且确保Python重新编译以使用新的OpenSSL版本这将是解决这个问题的最直接方法。这通常涉及到安装新版本的OpenSSL然后重新编译Python以确保它链接到新的库。 降级urllib3 如果升级OpenSSL不可行或太复杂你可以考虑降级urllib3到一个与你的OpenSSL版本兼容的版本。你可以使用pip来降级 bash pip install “urllib32.0” 这将安装一个低于2.0版本的urllib3该版本应该与你的OpenSSL 1.1.0h兼容。 使用虚拟环境 如果你不想在系统级别更改OpenSSL或urllib3你可以创建一个新的Python虚拟环境并在其中安装一个与当前系统OpenSSL版本兼容的urllib3版本。使用venv或conda创建新环境并在其中安装所需的库版本。 检查系统依赖 确保你的操作系统和所有相关的库都是最新的有时候操作系统更新会包含对OpenSSL的更新。 查看错误链接 错误信息中提供了一个链接https://github.com/urllib3/urllib3/issues/2168你可以访问这个链接查看是否有其他用户遇到类似问题以及他们是如何解决的。 选择哪种方法取决于你的具体需求和系统配置。如果你不确定如何操作可能需要寻求一个有经验的系统管理员或开发者的帮助。
执行
(.venv) PS E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest pip install “urllib32.0” Collecting urllib32.0 Obtaining dependency information for urllib32.0 from https://files.pythonhosted.org/packages/33/cf/8435d5a7159e2a9c83a95896ed596f68cf798005fe107cc655b5c5c14704/urllib3-1.26.20-py2.py3-none-any.whl.metadata Downloading urllib3-1.26.20-py2.py3-none-any.whl.metadata (50 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 50.1/50.1 kB 169.6 kB/s eta 0:00:00 Downloading urllib3-1.26.20-py2.py3-none-any.whl (144 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 144.2/144.2 kB 119.1 kB/s eta 0:00:00 Installing collected packages: urllib3 Attempting uninstall: urllib3 Found existing installation: urllib3 2.0.7 Uninstalling urllib3-2.0.7: Successfully uninstalled urllib3-2.0.7 Successfully installed urllib3-1.26.20
[notice] A new release of pip is available: 23.2.1 - 24.0 [notice] To update, run: python.exe -m pip install --upgrade pip (.venv) PS E:\WorkContent\shanghaikaifangdaxue\pythontest\pythontest
最后生效 安装浏览器驱动-Firefox
安装Firefox浏览器。https://www.firefox.com.cn/
下载对应的驱动
网址https://github.com/mozilla/geckodriver/releases 翻到底部Assets处点击Show all asets
测试Firefox
在Firefox中安装Selenium IDE
点击进入选择添加到Firefox
勾选允许此扩展在隐私窗口中运行。可以不勾选但目前不清楚会产生什么问题还是勾选
此时在Firefox右上角出现Selenium IDE图标。