

mac 下使用 homebrew 安装 chrome
source link: https://blog.kelu.org/software/2023/12/26/mac-homebrew-instasll-chrome.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

mac 下使用 homebrew 安装 chrome

真是一波三折血泪史。
起因是要装 chromedriver,先看了官方的地址:https://chromedriver.chromium.org/downloads
怎么回事,不能装最新的,只能装114版本?

看样子 homebrew 的版本没有114的,还是用老一点的chrome版本,才能和官方稳定的 chromedriver 搭配干活。
brew info --cask google-chrome
brew install --cask google-chrome@114

完了,homebrew没有这个版本。网上乱七八糟的不放心,还是找比较像官方的:

下载下来发现用不了,无法运行。

算了,直接源码编译:https://chromium.googlesource.com/chromium/src/+refs
我用了114版本:https://chromium.googlesource.com/chromium/src/+/refs/tags/114.0.5735.346
放弃,怎么可能自己编译?!

又认真看了下,120和对应的chromedriver,这不是有吗?https://googlechromelabs.github.io/chrome-for-testing/


下载好了还是无法运行,心累了。

死马当活马医吧,用 homebrew 把 chrome 和 chromedriver 都装完:

试着跑一下 selenium-server 看:

没问题。用代码跑看也是OK的。写了个简单的动态加载另一个python文件的方法,适合debug。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
import os
import subprocess
import random
import importlib
USERNAME=""
PASSWORD=""
WEBSITE="http://abc.com"
driver = webdriver.Chrome()
module_name = "oaread"
oaread_module = importlib.import_module(module_name)
def main():
global WEBSITE
global driver
driver.get(WEBSITE)
print('Enter ' + driver.title)
# time.sleep(random.randint(4,9))
username_xpath = '//input[contains(@id,"userName")]'
password_xpath = '//input[contains(@id,"password")]'
login_button_xpath = '//*[@id="main"]/table/tbody/tr/td/div[2]/div/login-tab/div/div[2]/div[2]/div[1]'
try:
username_elem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, username_xpath))
)
# 输入用户名
username_elem.send_keys(USERNAME)
# print(username_elem.get_attribute('outerHTML'))
# 等待密码输入框可见
password_elem = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, password_xpath))
)
# 输入密码
password_elem.send_keys(PASSWORD)
# print(password_elem.get_attribute('outerHTML'))
# 添加等待时间,模拟人为操作的速度
time.sleep(1)
# 等待登录按钮可见
login_button_elem = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, login_button_xpath))
)
# 点击登录按钮
login_button_elem.click()
step_enter_oaread(driver)
except Exception as e:
print(e)
# step_oa_read(driver)
monitor_and_execute(module_name+".py", driver)
def get_file_modification_time(file_path):
"""
获取文件的修改时间
"""
return os.path.getmtime(file_path)
def monitor_and_execute(script_path, driver):
"""
监控文件是否有更新,如果有更新则执行脚本
"""
last_modification_time = get_file_modification_time(script_path)
while True:
current_modification_time = get_file_modification_time(script_path)
if current_modification_time > last_modification_time:
print("File has been updated. Executing the script.")
last_modification_time = current_modification_time
importlib.reload(oaread_module)
try:
oaread_module.my_run(driver)
except Exception as e:
print("执行出错,不管了")
print(e)
print("sleep 1")
time.sleep(1)
def step_oa_read(driver):
errCount = 10
while errCount > 0:
try:
oaread_module.step_first_item(driver)
time.sleep(random.randint(2,4))
oaread_module.step_item_replay(driver)
except Exception as e:
errCount -= 1
print(e)
print("执行出错,不管了")
time.sleep(random.randint(10,20))
time.sleep(random.randint(1,2))
oaread_module.my_first_window(driver)
def step_enter_oaread(driver):
driver.get('http://abc.com)
if __name__=="__main__":
errCount = 10
while errCount > 0:
errCount -= 1
main()

Recommend
-
11
在 M1 芯片 Mac 上使用 HomebrewiOS话题下的优秀回答者Homebrew 是 Mac 上管理软件包的最实用工具之一。但截至目前,它还没有对搭载 Apple silicon 的新 Mac 机型完成适配。根据维...
-
24
« back — written by Brent on November 26, 2020 Upgrade to PHP 8 with Homebrew on Mac ...
-
12
Mac上的Homebrew安装和oh my zsh安装等相关问题全部评论0只看作者按时间倒序按时间正序推荐阅读...
-
5
MAC Homebrew 国内如何安装(国内地址) 第一步:通过命令删除之前的 brew、创建一个新的 Homebrew 文件夹sudo rm -rf /usr/local/Homebrew sudo mkdir /usr/local/Homebrew ...
-
4
在 Linux 上安装和使用 Homebrew 包管理器 | Linux 中国Homebrew(家酿),也被称为 Brew,是一个主要为 macOS 创建的命令行包管理器。来源:
-
5
Homebrew(家酿),也被称为 Brew,是一个主要为 macOS 创建的命令行包管理器。 Homebrew 在 macOS 用户中相当流行,因为更多的开发者创造了可以用 Homebrew 轻松安装的命令行工具。 这种流行导致了 Linuxbrew 的诞生,它是 Homebrew 的一个 Linux...
-
9
在 Mac 上使用 Homebrew 升级PHP到 PHP 8.1 发布:3个月前 更新:3个月前...
-
5
使用HomeBrew安装回滚软件到指定版本 发表于 2019-06-11 | 分类于 技术控 |
-
3
使用 Homebrew 升级 首先确保 brew 是最新的: brew update 接下来,升级PHP。您可以使用内置的 php 配方,但我建议使用shivammathur/homebrew-php。
-
3
Homebrew 是使用 ruby 语言写的 Mac 系统的包管理工具 (也有 Linux 版本), 在系统默认没有提供相关包的情况下发挥作用. 大多是工程类没有图形界面的包.Homebrew 的优点是能够判断系统中已经有的组件而不会重复下载, 其他的包管理工具如 MacPorts...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK