首页
Search
1
v2ray异常错误之二
3,310 阅读
2
linux时区设置
2,698 阅读
3
DB2常用操作
2,173 阅读
4
websphere修改jvm内存xmx和xms
1,929 阅读
5
nfs客户端文件属主为nobody的现象
1,552 阅读
技术
生活
运动
游戏
电影
登录
Search
标签搜索
docker
linux
troubleshooting
nginx
secure
truenas
mysql
windows
python
esxi
docker swarm
oracle
zabbix
tomcat
blog
dsm
群晖
rpa
freenas
db
yuc
累计撰写
291
篇文章
累计收到
0
条评论
首页
栏目
技术
生活
运动
游戏
电影
页面
搜索到
4
篇与
的结果
2024-06-28
selenium使用的功能技巧
0x0 selenium连接浏览器 chrome_options = Options() chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") driver = webdriver.Chrome(options=chrome_options) 0x1 selenium获取cookie cookies = driver.get_cookies() session = requests.Session() for cookie in cookies: # print(f"{cookie['name']} -> {cookie['value']}") session.cookies.set(cookie['name'], cookie['value']) 0x2 selenium导出页面源码 driver.execute_script('return document.documentElement.outerHTML') 0x3 selenium如何切换标签页 if type == 'main': # 切换回主页 driver.switch_to.window(mainhandleid) else: # 切换回dbid页 all_handles = driver.window_handles for handle in all_handles: if handle != mainhandleid: driver.switch_to.window(handle) Logging('切换tab成功') break
2024年06月28日
7 阅读
0 评论
0 点赞
2024-06-27
selenium初始化浏览器很慢的问题
问题 selenium初始化浏览器的异常现象: 所需时间很长且不稳定(可能在数分钟到十来分钟),在等待这些时间后可以正常初始化并且使用 原因 我的代码如下: chrome_options = Options() Logging('设置selenium参数中1') chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222") Logging('设置selenium参数中2') driver = webdriver.Chrome(options=chrome_options) Logging('设置selenium参数完毕','info') 在三个阶段进行了测试,发现到最后 webdriver.Chrome 这里很慢,可以确定是这里的问题 经过了搜索之后发现这个问题的原因是高版本现在初始化的时候会去外网请求api来对比版本,很显然我们的网络环境是访问不到的,所以最终会超时 Exception managing chrome: error sending request for url (https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json) 这个是手动测试的时候抛出来的地址 解决方法 解决这个问题也很简单,方案有两个: 使用代理让机器能够访问到外网,这样就不会有问题了 把这个地址使用本地解析到内网,这样出错了也可以快速返回 鉴于我们以后都是使用的内网环境,无需外部网络,并且已经下载好了对应的版本,所以最终采用第二种方式,在 /etc/hosts 中增加如下内容: 127.0.0.255 googlechromelabs.github.io PS. 为什么经过了一系列的搜索才知道解决方案? 因为前面测试的时候除了时间慢,并没有给出任何异常,所以 selenium 如何打印 debug 信息呢?
2024年06月27日
5 阅读
0 评论
0 点赞
2022-06-18
win和mac下selenium
0x1 什么问题 一般我们使用linux操作系统,会把chromedriver或者chrome浏览器放入环境变量,那么用户selenium调用server的时候无需指定任何路径。但是有时候我们本地win或者mac做selenium server绿色版,不想把浏览器/chromedriver放入环境变量中,那应该怎么办呢? 0x2 指定路径 这里以chrome浏览器为例,客户端调用的时候是可以传入chrome路径的,这样的话,服务端浏览器不必强制放入环境变量中 #!/bin/python3 # -*- coding: utf-8 -*- # mac下: 使用/Users/yuc/Desktop/123456/chrome/google/Chromium.app,这个路径在macos是能够打开chrome浏览器的,但是selenium必须要定位到后面的Chromium # win下: 路径需要使用\\ # 类unix下: 最好加上--no-sandbox,默认root是不允许启动chrome的 import selenium from selenium import webdriver #bpath = '/usr/bin/google-chrome' #bpath = '/Users/yuc/Desktop/123456/chrome/google/Chromium.app/Contents/MacOS/Chromium' #bpath = '/Users/yuc/Desktop/123456/packagefiles/mac/chrome/Chromium.app/Contents/MacOS/Chromium' #bpath = 'C:\\App\\code\\bi-bins\\packagefiles\\win\\chrome\\chrome.exe' chrome_options = webdriver.chrome.options.Options() #url = 'http://192.168.3.151:4444/wd/hub' #url = 'http://192.168.13.60:4444/wd/hub' url = 'http://192.168.3.151:10444/wd/hub' chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--headless') chrome_options.add_argument('--lang=zh_CN') #chrome_options.binary_location = bpath print (chrome_options.binary_location) dc = "" driver = webdriver.chrome.webdriver.RemoteWebDriver(command_executor=url, desired_capabilities=chrome_options.to_capabilities()) #driver = webdriver.remote.webdriver.WebDriver(command_executor=url, desired_capabilities=chrome_options.to_capabilities()) driver.get('https://dev.succez.com') print(driver.page_source) driver.quit()
2022年06月18日
757 阅读
0 评论
0 点赞
2022-05-10
selenium在linux下截图乱码
Linux下解决乱码问题 现象:之前在windows上运行,截图内容显示正常 问题:脚本转移到linux上,截图发现中文部分出现很多框框。测试截图多个网页都是,怀疑是没有中文字体。 处理:加入中文字体,可以选择任意免费使用的中文字体加入操作系统即可 # 安装必要软件 yum -y install fontconfig xorg-x11-font-utils # 新建目录 mkdir -pv /usr/share/fonts/chinese # 支持的中文字体放入 # 字体生效 mkfontscale && mkfontdir && fc-cache -fv && fc-list
2022年05月10日
1,007 阅读
0 评论
0 点赞