当前位置: 首页 > news >正文

懒人凳子网站建设策划书上海疫情最新消息

懒人凳子网站建设策划书,上海疫情最新消息,安徽做网站找谁,做全房订制网站公司1.搭建环境 1.安装: pip install msedge-selenium-tools 不要使用pip install selenium,我的电脑上没法运行 2.下载驱动 Microsoft Edge WebDriver |Microsoft Edge 开发人员 edge浏览器点设置---关于即可找到版本号,一定要下载对应版…

1.搭建环境

1.安装:

pip install msedge-selenium-tools

不要使用pip install selenium,我的电脑上没法运行

2.下载驱动  

Microsoft Edge WebDriver |Microsoft Edge 开发人员

edge浏览器点设置---关于即可找到版本号,一定要下载对应版本的驱动 

我的电脑是64位的,下载了x64的,但是运行时报错:OSError: [WinError 216] 该版本的 %1 与你运行的 Windows 版本不兼容。请查看计算机的系统信息,然后联系软件发布者。

下载win32的selenium解决

又报错:ValueError: Timeout value connect was <object object at 0x000001C609CC8630>, but it must be an int, float or None.

python selenium报错ValueError: Timeout value connect was <...>, but it must be an int, float or None._raise valueerror( valueerror: timeout value connec-CSDN博客

python selenium报错ValueError: Timeout value connect was <...>, but it must be an int, float or None._raise valueerror( valueerror: timeout value connec-CSDN博客 

 继续报错:ModuleNotFoundError: No module named 'urllib3.packages.six.moves'
pip show selenium
Name: selenium
Version: 3.141.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: C:\Users\15269\AppData\Local\Programs\Python\Python312\Lib\site-packages
Requires: urllib3
Required-by: msedge-selenium-tools

重装1.26.12的urllib3解决(我使用的是python3.12)如果还不行就多换几个试试 

测试代码
from msedge.selenium_tools import Edge, EdgeOptionsoptions = EdgeOptions()
options.use_chromium = True
options.add_experimental_option('excludeSwitches',['enable-automation'])  # 开启开发者模式
options.add_argument('--disable-blink-features=AutomationControlled')  # 禁用启用Blink运行时的功能
options.binary_location = r'C:\Program Files (x86)\Microsoft\EdgeCore\113.0.1774.50\msedge.exe'
url = 'https://www.baidu.com/'driver = Edge(options=options, executable_path='./msedgedriver.exe')
driver.get(url)

二、带有用户数据的爬虫参考

以下内容转载自这位大佬的博客:

使用 Selenium 启动的 Chrome 浏览器,默认是无法使用本地数据的,如表单项、密码、Cookies 等。

原因分析

这是由于 Selenium 在启动 Chrome 时,默认将命令行参数 --user-data-dir(该参数用于设置用户数据目录)设为了一个“临时目录”,如下图所示:

在 Selenium 启动的 Chrome 浏览器的地址栏中输出 chrome://version 并回车,就可以打开上图这个界面。

查看默认的用户数据目录的

手动打开一个 Chrome 浏览器,在地址栏中输出 chrome://version 并回车,找到 Profile Path: 后面的路径,去掉最后的 \Default,就是默认的用户数据目录,它一般都是:C:\Users\Your_User_Name\AppData\Local\Google\Chrome\User Data

将默认的用户数据目录设为 Selenium 启动的 Chrome 的用户数据目录

代码如下:

import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Serviceoptions = webdriver.ChromeOptions()
options.add_argument(r'user-data-dir=C:\Users\Your_User_Name\AppData\Local\Google\Chrome\User Data')
#  --user-data-dir 前的两个短杠似乎有没有均可browser = webdriver.Chrome(options=options,service=Service()  # 需要将 Chrome 驱动放在此文件的同一目录下
)browser.get('https://mail.163.com/')   # 此处以 163 邮箱为例,因为 163 邮箱的 Cookies 可以在本地保存 30 天。
time.sleep(120)

对于edge浏览器:edge://version/

三、实战应用

stm官网登录

登陆界面网址:登录注册 (stmicroelectronics.cn)

右键检查,找到用户名&密码&登录按钮的路径,并写出相应js代码。之后在控制台测试

document.getElementById("username").value = "你的用户名"
document.getElementById("password").value = "你的密码"
document.querySelector(".an_lan").click() //登录

 完整代码

from msedge.selenium_tools import Edge, EdgeOptionsclass Demo:def __init__(self) -> None:#keep alive为True,即处理完后不会关闭edgeoptions = EdgeOptions()options.use_chromium = Trueoptions.add_experimental_option('excludeSwitches',['enable-automation'])  # 开启开发者模式#用户数据#options.add_argument(r'user-data-dir=C:\Users\15269\AppData\Local\Microsoft\Edge\User Data')options.add_argument('--disable-blink-features=AutomationControlled')  # 禁用启用Blink运行时的功能options.binary_location = r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe'self.webdriver = Edge("./msedgedriver.exe", keep_alive=True, options=options)self.login_url = r"https://sso.stmicroelectronics.cn/User/LoginByPassword"self.username = "。。。"self.password = "@。。。"def login(self):payload = f"""document.getElementById("username").value = "{self.username}"document.getElementById("password").value = "{self.password}"document.querySelector(".an_lan").click() //登录"""self.webdriver.get(self.login_url)self.webdriver.execute_script(payload)def run(self):self.login()if __name__ == "__main__":Demo().run()

http://www.hkea.cn/news/338978/

相关文章:

  • 建设网站查证书网络广告有哪些形式
  • 分布式网站开发网络销售平台排名
  • 网站建设模板购买品牌seo培训
  • 深圳网站建设 cms网站推广交换链接
  • 标准物质网站建设5118站长工具箱
  • 做一个能注册用户的网站网络推广费用大概价格
  • 网站建设评价东莞谷歌推广
  • php网站后台进不去百度推广入口官网
  • 个人网站一键生成免费推广网站有哪些
  • 厦门做网站设计电商seo优化
  • wordpress视频点播seo技术是干什么的
  • 网站推广是怎么做的网络营销专业如何
  • 平面设计线上兼职上海网站seo
  • 个性化网站定制价格今日热点
  • 做网站的艰辛免费个人网站申请
  • 网站改版需要多久网站设计与制作毕业论文范文
  • 深圳横岗网站建设网站建设的推广渠道
  • 有没有什么网站免费做名片2023年新闻小学生摘抄
  • 新网金商网站外链查询工具
  • 网站建设的进度竞价托管选择微竞价
  • 网站快速网站推广怎么做一个公司网站
  • 旅游网站模板htmlseo品牌优化整站优化
  • 方圆网站建设aso优化重要吗
  • 做购实惠网站的意义好用的搜索引擎有哪些
  • 怎么把自己笔记本做服务器做个网站搭建网站基本步骤
  • jeecms做企业网站成都网站建设公司排名
  • 沈阳招聘网站开发地推项目平台
  • 798艺术区成都seo达人
  • 平度网站建设抖音代运营收费详细价格
  • 株洲网站优化找哪家seo优化的价格