<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Selenium &#8211; wqh博客</title>
	<atom:link href="https://wangqianhong.com/tag/selenium/feed/" rel="self" type="application/rss+xml" />
	<link>https://wangqianhong.com</link>
	<description>和而不同</description>
	<lastBuildDate>Mon, 04 Aug 2025 10:11:18 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wangqianhong.com/wp-content/uploads/2020/09/cropped-1-1-1-32x32.png</url>
	<title>Selenium &#8211; wqh博客</title>
	<link>https://wangqianhong.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Selenium（一） &#124; Debian环境搭建</title>
		<link>https://wangqianhong.com/2024/05/selenium-debian%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/</link>
					<comments>https://wangqianhong.com/2024/05/selenium-debian%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Sat, 04 May 2024 00:36:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[Selenium]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=3874</guid>

					<description><![CDATA[<p>Python + Selenium 完全可以在 Debian 上运行。大致流程分两步： 安装 Goo&#8230; <a href="https://wangqianhong.com/2024/05/selenium-debian%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Selenium（一） &#124; Debian环境搭建</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2024/05/selenium-debian%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/">Selenium（一） | Debian环境搭建</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>Python + Selenium 完全可以在 Debian 上运行。大致流程分两步：</p>



<ol><li>安装 Google Chrome 浏览器</li><li>安装 Python、Selenium 及对应的 ChromeDriver</li></ol>



<p>下面以 Debian 11 (“Bullseye”) 为例，演示具体命令。</p>



<h3>在 Debian 上安装 Google Chrome</h3>



<p>Google 官方并不把 Chrome 放到 Debian 默认源，需要先添加 Google 的 apt 仓库。</p>



<pre class="wp-block-preformatted"># 1. 更新本地包列表
<code>sudo apt update</code>

# 2. 安装必要工具
<code>sudo apt install -y wget gnupg2 apt-transport-https ca-certificates</code>

# 3. 导入 Google 的公钥
<code>wget -q -O - https://dl.google.com/linux/linux_signing_key.pub \
| sudo gpg --dearmor -o /usr/share/keyrings/google-linux-signing-keyring.gpg</code>

# 4. 添加 Google Chrome 的 apt 源
<code>echo "deb [signed-by=/usr/share/keyrings/google-linux-signing-keyring.gpg] \
http://dl.google.com/linux/chrome/deb/ stable main" \
| sudo tee /etc/apt/sources.list.d/google-chrome.list</code>

# 5. 再次更新并安装 Chrome
<code>sudo apt update
sudo apt install -y google-chrome-stable</code></pre>



<p>安装完成后，你可以用 <code>google-chrome --version</code> 验证版本。</p>



<h3>安装 Python、Selenium 及 ChromeDriver</h3>



<h4>安装 Python 和 pip</h4>



<p>Debian 11 默认带有 Python3，但可以确保安装最新：</p>



<pre class="wp-block-code"><code>sudo apt install -y python3 python3-venv python3-pip</code></pre>



<h4>安装 Selenium</h4>



<pre class="wp-block-preformatted"># 建议在 virtualenv 中安装
<code>python3 -m venv ~/selenium-env
source ~/selenium-env/bin/activate</code>

# 安装 Selenium 库
<code>pip install --upgrade pip
pip install selenium</code></pre>



<p>如果安装比较慢，可以使用国内镜像源：</p>



<pre class="wp-block-code"><code>pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple</code></pre>



<p>安装 ChromeDriver</p>



<p>ChromeDriver 必须与 Chrome 浏览器版本匹配。可手动下载，也可用 <code>webdriver-manager</code> 自动管理。</p>



<h5>方案 A：手动下载</h5>



<ol><li>查询 Chrome 版本： <code>google-chrome --version </code># 比如输出：Google Chrome <code>115.0.5790.98</code></li><li>到 <a href="https://chromedriver.storage.googleapis.com/index.html">https://chromedriver.storage.googleapis.com/index.html</a> 找到对应的 “115.0.5790.98” 版本，下载 Linux x64 zip。</li><li>解压并移动到 <code>/usr/local/bin</code>： <code>wget -O chromedriver_linux64.zip \ https://chromedriver.storage.googleapis.com/115.0.5790.98/chromedriver_linux64.zip unzip chromedriver_linux64.zip sudo mv chromedriver /usr/local/bin/ sudo chmod +x /usr/local/bin/chromedriver</code></li></ol>



<h5>方案 B：自动管理（推荐开发环境）</h5>



<pre class="wp-block-code"><code>pip install webdriver-manager</code></pre>



<p>在脚本中使用时，示例代码：</p>



<pre class="wp-block-code"><code>from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

# 自动下载并启动
service = Service(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
# 如果在无头服务器上运行，加上下面两行：
# options.add_argument('--headless')
# options.add_argument('--no-sandbox')

driver = webdriver.Chrome(service=service, options=options)
driver.get("https://www.example.com")
print(driver.title)
driver.quit()</code></pre>



<p>完成以上步骤后，就可以在 Debian 上用 Python + Selenium + ChromeDriver 驱动真实的 Chrome 浏览器来做自动化测试或爬虫／RPA 了。</p>
<p><a rel="nofollow" href="https://wangqianhong.com/2024/05/selenium-debian%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/">Selenium（一） | Debian环境搭建</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2024/05/selenium-debian%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
