
为提升日常网页访问效率,搭建一个本地 Web 服务作为浏览器默认主页,管理日常经常访问的网站地址。具体方案为:在本地计算机上运行一个简易 HTTP 服务器,托管一个定制化的 HTML 页面。该页面将整合常用的网站链接,以直观的列表形式呈现,涵盖工作、学习、娱乐等分类。通过将浏览器默认主页设置为本地服务器地址(如http://localhost),每次打开浏览器即可快速访问常用网址,无需手动输入或翻找收藏夹,从而节省时间,提升效率。此方案兼顾灵活性与个性化,可随时根据需求更新链接列表。
1、创建并python虚拟环境
cd path/to/your/project
python -m venv venv
path/to/your/project/scripts/activate2、创建网站主目录启动python web server
mkdir path/www
cd path/www
python -m http.server 80003、创建html web页面
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>马克思主义者导航平台</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Microsoft YaHei', Arial, sans-serif;
line-height: 1.6;
background: #f0f2f5;
color: #333;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
.header {
text-align: center;
padding: 40px;
background: linear-gradient(45deg, #dc3545, #bd2130);
color: white;
border-radius: 10px;
margin-bottom: 30px;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 15px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
.nav {
background: #fff;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 30px;
}
.nav a {
color: #dc3545;
text-decoration: none;
margin: 0 15px;
font-weight: 500;
transition: color 0.3s;
}
.nav a:hover {
color: #bd2130;
}
.grid-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 30px;
margin-bottom: 30px;
}
.category-card {
background: white;
padding: 25px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
transition: transform 0.2s;
}
.category-card:hover {
transform: translateY(-5px);
}
.category-title {
color: #dc3545;
border-bottom: 2px solid #eee;
padding-bottom: 10px;
margin-bottom: 15px;
font-size: 1.2em;
display: flex;
align-items: center;
}
.category-title::before {
content: attr(data-icon);
font-size: 1.5em;
margin-right: 10px;
}
.link-list a {
display: block;
color: #333;
padding: 8px 15px;
margin: 5px 0;
background: #f8f9fa;
border-radius: 5px;
text-decoration: none;
transition: all 0.3s;
}
.link-list a:hover {
background: #dc3545;
color: white;
transform: translateX(10px);
}
.calendar-container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
position: fixed;
right: 30px;
top: 30px;
width: 300px;
z-index: 100; /* 确保浮层显示 */
}
.calendar-header {
text-align: center;
font-weight: bold;
margin-bottom: 10px;
color: #dc3545;
}
.calendar {
min-height: 60px; /* 防止内容塌陷 */
}
.loading {
color: #999;
text-align: center;
padding: 15px 0;
}
.quote {
margin-top: 15px;
padding-top: 15px;
border-top: 1px solid #eee;
font-size: 0.85em;
color: #666;
line-height: 1.4;
position: relative;
}
.quote::before {
content: "“";
position: absolute;
left: -10px;
top: -5px;
font-size: 2em;
color: #dc3545;
line-height: 0;
}
.quote-source {
text-align: right;
font-style: italic;
margin-top: 5px;
color: #999;
}
.footer {
text-align: center;
padding: 20px;
color: #666;
margin-top: 50px;
border-top: 1px solid #eee;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🌍 马克思主义导航平台</h1>
<p>实践是检验真理的唯一标准 —— 坚持人民立场,服务生产实践</p>
</div>
<div class="nav">
<a href="#study">理论学习</a>
<a href="#news">时事新闻</a>
<a href="#tools">生产工具</a>
<a href="#culture">红色文化</a>
<a href="#health">身心健康</a>
<a href="#local">本地服务</a>
</div>
<div class="grid-container">
<!-- 理论学习分类 -->
<div class="category-card" id="study">
<div class="category-title" data-icon="📚">理论学习</div>
<div class="link-list">
<a href="https://www.marxists.org/" target="_blank">马克思主义文库</a>
<a href="https://www.sscp.cn/" target="_blank">中国社会科学网</a>
<a href="https://www.19th.cn/" target="_blank">求是网</a>
</div>
</div>
<!-- 时事新闻分类 -->
<div class="category-card" id="news">
<div class="category-title" data-icon="📰">时事新闻</div>
<div class="link-list">
<a href="https://www.people.com.cn/" target="_blank">人民网</a>
<a href="https://www.xinhuanet.com/" target="_blank">新华网</a>
<a href="https://www.chinanews.com/" target="_blank">中国新闻网</a>
</div>
</div>
<!-- 生产工具分类 -->
<div class="category-card" id="tools">
<div class="category-title" data-icon="⚙️">生产工具</div>
<div class="link-list">
<a href="https://www.processon.com/" target="_blank">在线流程图</a>
<a href="https://www.typora.io/" target="_blank">Markdown编辑器</a>
<a href="https://git-scm.com/" target="_blank">Git版本控制</a>
</div>
</div>
<!-- 红色文化分类 -->
<div class="category-card" id="culture">
<div class="category-title" data-icon="🇨🇳">红色文化</div>
<div class="link-list">
<a href="http://www.cpc.people.com.cn/" target="_blank">人民网党建频道</a>
<a href="https://www.rmkxb.com.cn/" target="_blank">红色文化网</a>
<a href="https://www.81cn.cn/" target="_blank">中国军网</a>
</div>
</div>
<!-- 身心健康分类 -->
<div class="category-card" id="health">
<div class="category-title" data-icon="❤️">身心健康</div>
<div class="link-list">
<a href="https://www.who.int/zh" target="_blank">世界卫生组织</a>
<a href="https://yundong.360.cn/" target="_blank">360运动健康</a>
<a href="https://www.xinli001.com/" target="_blank">壹心理</a>
</div>
</div>
<!-- 本地服务分类 -->
<div class="category-card" id="local">
<div class="category-title" data-icon="🏙️">本地服务</div>
<div class="link-list">
<a href="https://www.zfwfw.gov.cn/" target="_blank">政务服务网</a>
<a href="https://www.12306.cn/" target="_blank">铁路12306</a>
<a href="https://www.ctrip.com/" target="_blank">携程旅行</a>
</div>
</div>
</div>
<div class="calendar-container">
<div class="calendar-header">📅 今日黄历</div>
<div class="calendar" id="calendar">
<div class="loading">日历加载中...</div>
</div>
<div class="quote">
"时间实际上是人的积极存在,它不仅是人的生命的尺度,而且是人的发展的空间。"
<div class="quote-source">—— 卡尔·马克思《政治经济学批判大纲》</div>
</div>
</div>
<div class="footer">
<p>全心全意为人民服务 · 版本 1.0.0</p>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
function generateLunarCalendar() {
const calendar = document.getElementById('calendar');
const now = new Date();
// 增强日期格式兼容性
const options = {
year: 'numeric',
month: 'long',
day: 'numeric',
weekday: 'long',
timeZone: 'Asia/Shanghai'
};
try {
// 生成公历日期
const solarDate = now.toLocaleDateString('zh-CN', options);
// 生成农历日期(简化版)
const lunarMonths = [
'正月','二月','三月','四月','五月','六月',
'七月','八月','九月','十月','冬月','腊月'
];
const lunarDay = now.getDate() <= 10 ? '初' :
(now.getDate() <= 20 ? '十' :
(now.getDate() <= 30 ? '廿' : '三十'));
// 构建日历内容
const calendarContent = `
<div>公历:${solarDate}</div>
<div>农历:${lunarMonths[now.getMonth()]} ${lunarDay}${now.getDate() % 10 || '十'}</div>
`;
// 更新日历内容
calendar.innerHTML = calendarContent;
} catch (error) {
console.error('日历生成失败:', error);
calendar.innerHTML = '<div class="loading">日历加载失败,请刷新重试</div>';
}
}
// 立即执行并设置定时刷新
generateLunarCalendar();
setInterval(generateLunarCalendar, 60000);
});
</script>
</body>
</html>保存文件为 index.html,文件保存在path\www目录下。python http.server服务要在www目下开启。
4、设置开机自动开启
写批处理文件(start_python_server.bat),代码如下:
@echo off
chcp 65001 > nul
REM 脚本功能:激活虚拟环境并启动Python HTTP服务器
REM 设置虚拟环境路径(请根据实际情况修改)
set VENV_PATH=F:\mypy
REM 设置Web主页目录路径(请根据实际情况修改)
set WEB_DIR=F:\www
REM 检查虚拟环境是否存在
if not exist "%VENV_PATH%\Scripts\activate.bat" (
echo 错误:虚拟环境未找到于 %VENV_PATH%
pause
exit /b 1
)
REM 检查Web目录是否存在
if not exist "%WEB_DIR%" (
echo 错误:Web目录未找到于 %WEB_DIR%
pause
exit /b 1
)
REM 激活虚拟环境
call "%VENV_PATH%\Scripts\activate.bat"
if errorlevel 1 (
echo 错误:无法激活虚拟环境
pause
exit /b 1
)
REM 进入Web目录
pushd "%WEB_DIR%"
if errorlevel 1 (
echo 错误:无法进入目录 %WEB_DIR%
pause
exit /b 1
)
REM 启动Python HTTP服务器(默认端口8000)
echo 访问地址:http://localhost:8000
python -m http.server 8000
REM 服务器运行时会保持窗口打开,按Ctrl+C停止
REM 以下代码不会执行,因为服务器会持续运行
rem popd
rem deactivate用vb脚本设置批处理脚本(start_web.vbs)在后台运行,代码如下:
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "path\start_python_server.bat", 0, False5、设置windows开机自动启动
用Windows的“任务计划程序“,增加开机自动启动服务,开机时执行start_web.vbs脚本。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。