更简单的方法来下载Chrome驱动程序

7kjnsjlb  于 2023-05-11  发布在  Go
关注(0)|答案(2)|浏览(153)

我有一组测试,从https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb下载最新的Google Chrome,然后解析https://chromedriver.chromium.org/downloads上的内容,以确定要下载的正确Chrome驱动程序版本。Chrome版本:102.0.5005.115,并不总是与chrome驱动程序版本匹配,例如:102.0.5005.61.
目前,我解析https://chromedriver.chromium.org/downloads的内容并试图找出正确的版本。这是脆弱的,因为HTML内容可能会改变。

#!/bin/sh
GOOGLE_CHROME_VERSION="$(google-chrome --version | cut -f 3 -d ' ')"

# https://www.chromium.org/developers/version-numbers/
GOOGLE_CHROME_VERSION_MAJOR=$(echo "${GOOGLE_CHROME_VERSION}" | cut -f 1 -d'.')
echo "GOOGLE_CHROME_VERSION_MAJOR => [${GOOGLE_CHROME_VERSION_MAJOR}]"

# https://chromedriver.chromium.org/downloads
GOOGLE_CHROME_DRIVER_LINE=$(curl https://chromedriver.chromium.org/downloads | grep "If you are using Chrome version ${GOOGLE_CHROME_VERSION_MAJOR}," | head -1)
GOOGLE_CHROME_DRIVER_VERSION=$(echo "${GOOGLE_CHROME_DRIVER_LINE}" | rev | cut -f 1 -d' ' | rev)

echo "GOOGLE_CHROME_DRIVER_VERSION => [${GOOGLE_CHROME_DRIVER_VERSION}]"
wget https://chromedriver.storage.googleapis.com/${GOOGLE_CHROME_DRIVER_VERSION}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
rm chromedriver_linux64.zip
chmod a+x chromedriver
mv chromedriver /usr/local/bin

有没有更简单的方法来下载一个特定版本的google chrome的chrome驱动程序?

r1zk6ea1

r1zk6ea11#

https://chromedriver.chromium.org/downloads/version-selection
希望这能帮上忙。显然,它支持一些自动URL解析:

First, find out which version of Chrome you are using. Let's say you have Chrome 72.0.3626.81.

Take the Chrome version number, remove the last part, and append the result to URL "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_". For example, with Chrome version 72.0.3626.81, you'd get a URL "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_72.0.3626".

Use the URL created in the last step to retrieve a small file containing the version of ChromeDriver to use. For example, the above URL will get your a file containing "72.0.3626.69". (The actual number may change in the future, of course.)

Use the version number retrieved from the previous step to construct the URL to download ChromeDriver. With version 72.0.3626.69, the URL would be "https://chromedriver.storage.googleapis.com/index.html?path=72.0.3626.69/".

After the initial download, it is recommended that you occasionally go through the above process again to see if there are any bug fix releases.
ar7v8xwq

ar7v8xwq2#

此shell脚本将下载最新的chrome驱动程序并更新到Linux中的最新google chrome版本。

#!/bin/sh
#get latest version
version=`curl http://chromedriver.storage.googleapis.com/LATEST_RELEASE)`;
echo 'Currently LATEST_RELEASE:' $version;
#download the latest version chrome driver available as per the above line
wget -N http://chromedriver.storage.googleapis.com/${version}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip -d /usr/local/bin
chmod a+x /usr/local/bin/chromedriver
#upgrade to latest google chrome 
yum upgrade google-chrome-stable
google_version=`google-chrome --version`;
echo 'Google Chrome Version:' $google_version;
echo 'Currently LATEST_RELEASE:' $version;
echo 'End of the script'

如果您的Linux服务器已安装了操作系统补丁,则可以通过Cron Scheduler自动更新以指定的频率进行更新。Google Chrome每六周发布一次。事实上,最好使用最新的chrome来避免安全漏洞。因此,crontab将派上用场,以保护您的安全。

相关问题