网站TDK抓取API快速获取教程

在当今数字化浪潮中,网站TDK(即Title标题、Description描述、Keywords关键词)的精准抓取与分析,已成为SEO优化、竞品研究和数据聚合的基石。一个高效可靠的TDK抓取API,能极大提升工作效率。本文将为您呈现一份详尽的API使用教程,并深入剖析10个核心使用技巧与5大常见问题解答,助您快速掌握这门实用技能。


第一部分:网站TDK抓取API快速入门教程

要快速获取网站TDK,通常需要借助专用的API服务。其核心流程如下:
1. 选择API服务商:市面上有众多提供网页内容抓取服务的API供应商,如ScraperAPI、ZenRows等。您需根据预算、请求频率和功能需求进行选择,并注册获取唯一的API密钥。
2. 理解API端点与参数:大多数API通过一个简单的HTTP GET请求工作。您需要将目标网址作为参数(常为url=)传递给API端点。部分高级API支持设置超时、返回格式(JSON/HTML)、代理等参数。
3. 构建并发送请求:使用任何您熟悉的编程语言(如Python的Requests库、Node.js的Axios等)构建HTTP请求。请求中务必包含您的API密钥,通常通过请求头或查询参数传递。
4. 解析与提取TDK:API返回的通常是结构化的JSON数据或完整的HTML源代码。您需要从中定位并提取标签的内容作为Title,<meta name="description" content="...">的内容作为Description,以及<meta name="keywords" content="...">的内容作为Keywords。正则表达式或HTML解析库(如BeautifulSoup)可完成此项工作。<br> 5. <strong>错误处理与重试机制</strong>:网络请求充满不确定性,务必在代码中添加完善的错误处理(如处理404、403、500状态码、超时等),并为可重试的错误(如网络波动)设置指数退避的重试机制。 </p> <hr> <p class=article> <h3>第二部分:10个提升效率与稳定性的核心使用技巧</h3> 掌握基础操作后,以下技巧能让您的抓取工作如虎添翼:<br> <strong>技巧1:批量异步请求,突破速度瓶颈</strong><br> 顺序发送单个请求效率极低。利用Python的asyncio + aiohttp或Node.js的异步特性,并发发送数十甚至上百个请求,能将抓取速度提升数十倍,尤其适合大规模数据采集。<br> <strong>技巧2:设置智能延时,遵守Robots协议</strong><br> 不加节制的狂轰滥炸会导致IP被封。在请求间插入随机延时(如1-3秒),并优先检查目标网站的robots.txt文件,尊重Crawl-delay指令,这是可持续抓取的道德与技术要求。<br> <strong>技巧3:优先选用Headless浏览器模式应对JS渲染</strong><br> 许多现代网站依赖JavaScript动态生成TDK内容。常规HTTP请求获取的初始HTML中可能不包含这些信息。此时应选用支持Headless Chrome/Puppeteer模式的API,它能像真实浏览器一样执行JS,确保获取到完整的渲染后TDK。<br> <strong>技巧4:缓存结果,避免重复抓取浪费额度</strong><br> 对已成功抓取的URL及其TDK结果建立本地缓存数据库(如SQLite、Redis)。再次抓取前先查询缓存,仅对新增或缓存过期的URL发起API请求,能有效节省API调用额度和时间。<br> <strong>技巧5:精细化User-Agent轮换,模拟真实用户</strong><br> 单一固定的User-Agent容易被识别为爬虫。准备一个包含主流浏览器标识的UA池,每次请求随机轮换,可以更好地融入正常的流量背景中,降低被屏蔽的风险。<br> <strong>技巧6:结合元数据与正文分析,补全缺失信息</strong><br> 有些网站的Description或Keywords元标签可能为空。此时,可以策略性地截取页面正文(<p>标签)的前100-150个字符作为Description的备选,或通过TF-IDF等算法从正文中提取高频词作为Keywords的补充。<br> <strong>技巧7:监控API用量与预算,设置告警阈值</strong><br> 密切跟踪API服务的仪表盘,关注每日请求次数、成功率、费用消耗。设置用量达到80%或错误率骤增时的自动告警(通过邮件、钉钉、Slack等),避免额度超限导致业务中断。<br> <strong>技巧8:验证与清洗数据,确保输出质量</strong><br> 抓取的原始数据可能包含HTML实体(如&)、多余空白符或乱码。编写清洗函数,对Title和Description进行trim操作、解码HTML实体、移除不可见字符,保证存入数据库的数据干净规整。<br> <strong>技巧9:构建URL队列与任务调度系统</strong><br> 对于长期、定期的抓取任务(如监控竞品TDK变化),应设计一个可持久化的URL队列。结合Celery、Airflow等任务调度工具,实现定时、按优先级、自动重试的抓取工作流,使整个过程工业化、自动化。<br> <strong>技巧10:利用中间件处理反爬与验证码</strong><br> 当遇到复杂反爬机制(如Cloudflare的5秒盾)或验证码时,考虑集成第三方反破解服务(如2Captcha)的中间件,或切换至提供自动绕过功能的顶级API服务,将技术难题外包。 </p> <hr> <p class=article> <h3>第三部分:5大常见问题与专业解答</h3> 在实践过程中,以下问题是开发者们最常遇到的“拦路虎”:<br> <strong>问题1:API返回状态码403/404,或提示“Access Denied”,怎么办?</strong><br> <strong>解答</strong>:403通常意味着访问被拒绝。请检查:1)API密钥是否有效且未过期;2)目标网站是否有严格的防火墙(如WAF),尝试使用API服务商提供的代理或住宅IP池功能;3)请求头(尤其是User-Agent和Accept)是否设置得当。404则说明URL可能失效,请确认URL准确性。<br> <strong>问题2:抓取到的Title或Description是空的,或内容杂乱包含大量代码。</strong><br> <strong>解答</strong>:这通常是因为API返回了未经JavaScript渲染的初始HTML。解决方案见技巧3,切换到Headless浏览器模式。另外,检查您的解析规则是否正确,确保定位到了正确的HTML标签和属性。<br> <strong>问题3:抓取速度很慢,如何在不被封禁的前提下优化?</strong><br> <strong>解答</strong>:速度慢往往是单线程和延时过长导致。核心优化方案是“异步并发”与“智能延时”的结合(参见技巧1和2)。通过并发发送合理数量的请求(如10-20个),并为每个请求配置随机延时,可以在速度和友好度间取得最佳平衡。同时,选择 geographically closer 的API服务器节点也能降低网络延迟。<br> <strong>问题4:如何保证大规模、长期抓取任务的稳定性?</strong><br> <strong>解答</strong>:稳定性是系统工程。需要:1)<strong>健壮的架构</strong>:使用消息队列解耦抓取任务,实现断点续抓。2)<strong>全面的监控</strong>:监控API成功率、响应时间、目标网站结构变化。3)<strong>灵活的应变机制</strong>:当某个网站结构变化导致解析失败时,能快速更新解析规则并重新处理失败队列。4)<strong>备用方案</strong>:准备两套不同的API服务商作为备份,在主服务出现问题时无缝切换。<br> <strong>问题5:自行开发抓取程序与使用付费API,如何选择?</strong><br> <strong>解答</strong>:这是成本与精力的权衡。自行开发(使用开源库)初期成本低,但需要持续投入大量精力维护IP代理池、处理反爬更新、保证系统稳定,隐性成本很高。付费API(特别是企业级服务)提供“开箱即用”的稳定性、合规的代理网络和专业技术支持,将您从繁琐的运维中解放出来,专注于核心业务逻辑。对于商业级、对稳定性和规模有要求的项目,付费API通常是性价比更高的选择。 </p> <hr> <p class=article> <h3>结语</h3> 熟练掌握网站TDK抓取API,远不止于发送一个HTTP请求那么简单。它涉及到网络编程、反爬策略、数据清洗、系统架构等多方面的知识。通过本篇教程介绍的10个技巧,您可以构建出高效、稳定、可扩展的抓取系统;而对5个常见问题的深入理解,则能帮助您快速排错,保障流程畅通。在数据驱动的决策时代,让精准的TDK数据成为您洞察先机的有力武器。 </p> </div> <div class="article-actions"> <button class="action-btn like-btn" onclick="likeArticle(30600)"> <i class="fa fa-heart"></i> <span class="like-text">点赞</span> <span class="like-count">0</span> </button> <button class="action-btn share-btn" onclick="openShareModal()"> <i class="fa fa-share-alt"></i> 分享文章 </button> </div> </article> <nav class="article-navigation fade-in" style="animation-delay: 0.2s;"> <div class="nav-item"> <a href="http://007km.com/km/30599.html"> <div class="nav-label"><i class="fa fa-chevron-left"></i> 上一篇</div> <div class="nav-title">网站TDK抓取API如何使用?</div> </a> </div> <div class="nav-item"> <a href="http://007km.com/km/30607.html"> <div class="nav-label">下一篇 <i class="fa fa-chevron-right"></i></div> <div class="nav-title">百度收录量查询API上线,实时获取域名收录数</div> </a> </div> </nav> <section class="related-articles fade-in" style="animation-delay: 0.4s;"> <h3 class="related-title"> <i class="fa fa-list"></i> 相关文章 </h3> <ul class="related-list"> <li class="related-item"> <a href="http://007km.com/km/30601.html"> 百度收录API实时查询-掌握SEO域名收录数 </a> <div class="related-meta"> <span><i class="fa fa-calendar"></i> 2026-09-23</span> <span><i class="fa fa-eye"></i> 1 次浏览</span> </div> </li> <li class="related-item"> <a href="http://007km.com/km/30602.html"> 百度收录API - 域名收录数实时获取 </a> <div class="related-meta"> <span><i class="fa fa-calendar"></i> 2026-09-23</span> <span><i class="fa fa-eye"></i> 0 次浏览</span> </div> </li> <li class="related-item"> <a href="http://007km.com/km/30603.html"> 百度收录查询API,SEO效果实时见证 </a> <div class="related-meta"> <span><i class="fa fa-calendar"></i> 2026-09-23</span> <span><i class="fa fa-eye"></i> 0 次浏览</span> </div> </li> <li class="related-item"> <a href="http://007km.com/km/30604.html"> 百度收录查询API - SEO实时数据追踪 </a> <div class="related-meta"> <span><i class="fa fa-calendar"></i> 2026-09-23</span> <span><i class="fa fa-eye"></i> 0 次浏览</span> </div> </li> <li class="related-item"> <a href="http://007km.com/km/30605.html"> 百度收录API-实时秒查域名,SEO效果飙升! </a> <div class="related-meta"> <span><i class="fa fa-calendar"></i> 2026-09-23</span> <span><i class="fa fa-eye"></i> 0 次浏览</span> </div> </li> </ul> </section> </div> <div class="share-modal" id="shareModal"> <div class="share-modal-overlay" onclick="closeShareModal()"></div> <div class="share-modal-content"> <div class="share-modal-header"> <h3><i class="fa fa-share-alt"></i> 分享文章</h3> <button class="close-btn" onclick="closeShareModal()"> <i class="fa fa-times"></i> </button> </div> <div class="share-modal-body"> <div class="share-options"> <div class="share-option" onclick="shareToWeibo()"> <div class="share-icon weibo"> <i class="fa fa-weibo"></i> </div> <span>微博</span> </div> <div class="share-option" onclick="shareToQQ()"> <div class="share-icon qq"> <i class="fa fa-qq"></i> </div> <span>QQ</span> </div> <div class="share-option" onclick="shareToQzone()"> <div class="share-icon qzone"> <i class="fa fa-star"></i> </div> <span>QQ空间</span> </div> <div class="share-option" onclick="copyLink()"> <div class="share-icon copy"> <i class="fa fa-link"></i> </div> <span>复制链接</span> </div> </div> <div class="share-link-box"> <label>文章链接:</label> <div class="link-input-group"> <input type="text" id="articleLink" value="http://007km.com/km/30600.html" readonly> <button onclick="copyLinkFromInput()"> <i class="fa fa-copy"></i> 复制 </button> </div> </div> </div> </div> </div> <div class="share-toast" id="shareToast">操作成功</div> <script> function likeArticle(articleId) { const likeBtn = document.querySelector('.like-btn'); const likeCount = document.querySelector('.like-count'); const likeText = document.querySelector('.like-text'); if (localStorage.getItem('liked_' + articleId)) { showToast('您已经点过赞了'); return; } likeBtn.classList.add('animate'); setTimeout(() => likeBtn.classList.remove('animate'), 300); $.post('http://007km.com/ajax.php?act=dianzan', { type:2, id:'30600', }, function(data) { if (data.code ==200) { likeBtn.classList.add('liked'); likeText.textContent = '已赞'; likeCount.textContent = parseInt(likeCount.textContent) + 1; localStorage.setItem('liked_' + articleId, '1'); showToast('点赞成功'); } else { showToast(data.msg || '点赞失败'); } }, 'json').fail(function() { showToast('网络错误,请重试'); }); } function openShareModal() { document.getElementById('shareModal').classList.add('show'); document.body.style.overflow = 'hidden'; } function closeShareModal() { document.getElementById('shareModal').classList.remove('show'); document.body.style.overflow = ''; } function shareToWeibo() { const title = encodeURIComponent(document.title); const url = encodeURIComponent(window.location.href); window.open(`https://service.weibo.com/share/share.php?title=${title}&url=${url}`, '_blank', 'width=600,height=400'); closeShareModal(); } function shareToQQ() { const title = encodeURIComponent(document.title); const url = encodeURIComponent(window.location.href); const desc = encodeURIComponent('分享一篇精彩文章'); const summary = encodeURIComponent('来自本站的优质内容'); const shareUrl = `https://connect.qq.com/widget/shareqq/index.html?url=${url}&title=${title}&desc=${desc}&summary=${summary}`; window.open(shareUrl, '_blank', 'width=600,height=400'); closeShareModal(); } function shareToQzone() { const title = encodeURIComponent(document.title); const url = encodeURIComponent(window.location.href); const desc = encodeURIComponent('分享一篇精彩文章'); const shareUrl = `https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=${url}&title=${title}&desc=${desc}`; window.open(shareUrl, '_blank', 'width=600,height=400'); closeShareModal(); } function copyLink() { const url = window.location.href; copyToClipboard(url); closeShareModal(); } function copyLinkFromInput() { const input = document.getElementById('articleLink'); copyToClipboard(input.value); } function copyToClipboard(text) { if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(text).then(function() { showToast('链接已复制到剪贴板'); }).catch(function() { fallbackCopyText(text); }); } else { fallbackCopyText(text); } } function fallbackCopyText(text) { const textArea = document.createElement('textarea'); textArea.value = text; textArea.style.position = 'fixed'; textArea.style.left = '-9999px'; document.body.appendChild(textArea); textArea.select(); try { document.execCommand('copy'); showToast('链接已复制到剪贴板'); } catch (err) { showToast('复制失败,请手动复制链接'); } document.body.removeChild(textArea); } function showToast(message) { const toast = document.getElementById('shareToast'); toast.textContent = message; toast.style.display = 'block'; setTimeout(() => { toast.style.display = 'none'; }, 2000); } document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { closeShareModal(); } }); </script> <footer class="crystal-footer"> <div class="crystal-footer-bg"> <div class="crystal-footer-shapes"> <div class="crystal-footer-shape crystal-footer-shape-1"></div> <div class="crystal-footer-shape crystal-footer-shape-2"></div> <div class="crystal-footer-shape crystal-footer-shape-3"></div> </div> </div> <div class="crystal-friend-links-section"> <div class="crystal-friend-links-container"> <div class="crystal-friend-links-header"> <h3 class="crystal-friend-links-title"> <i class="layui-icon layui-icon-link"></i> 友情链接 </h3> <p class="crystal-friend-links-desc">这里收集了一些优质的网站资源,欢迎交流合作!</p> </div> <div class="crystal-friend-links-list"> <a href="https://www.yilianshuju.com/" target="_blank"class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://www.yilianshuju.com"><font color="#059309">API接口</font></a> <a href="https://www.zongxincha.com/" target="_blank"class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://www.zongxincha.com"><font color="#059309">综信查</font></a> <a href="https://yuanxiblog.cn/" target="_blank" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://yuanxiblog.cn/"><font color="#059309">远昔博客</font></a> <a href="http://yibazhan.cn/" target="_blank" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://yibazhan.cn/"><font color="#059309">易扒站</font></a> <a href="http://yichazhan.cn/" target="_blank" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://yichazhan.cn/"><font color="#059309">易查站</font></a> <a href="https://www.yuanxi8.cn/" target="_blank" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://yuanxiblog.cn/"><font color="#059309">远昔导航</font></a> <a href="https://www.yiguzhi.cn/" target="_blank" title="易估值" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://www.yiguzhi.cn/"><font color="#059309">易估值</font></a> <a href="https://www.hbdrxws.com/" target="_blank" title="助推者" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=https://www.hbdrxws.com/"><font color="#059309">助推者</font></a> <a href="http://www.081234.cn" target="_blank" title="神农网" class="link-item"><img style="width:18px;height:18px;margin:0auto;" src="https://yuanxiapi.cn/api/?id=28&key=6_83efcf5ff864b4998b6158804a51f3ad&url=http://www.081234.cn/"><font color="#059309">神农网</font></a> </div> </div> </div> <div class="crystal-footer-container"> <div class="crystal-footer-content"> <div class="crystal-footer-section"> <h3 class="crystal-footer-title"> <i class="fa fa-star"></i> 007卡盟 </h3> <p class="crystal-footer-desc"> 007卡盟专注品效合一推广方案,抖音代运营、KOL推广、内容合作、视频合作、品牌合作、达人资源等 </p> <div class="crystal-footer-stats"> <div class="crystal-stat"> <span class="crystal-stat-number">30378</span> <span class="crystal-stat-label">篇文章</span> </div> <div class="crystal-stat"> <span class="crystal-stat-number">2331155</span> <span class="crystal-stat-label">次阅读</span> </div> </div> </div> <div class="crystal-footer-section"> <h4 class="crystal-footer-subtitle"> <i class="fa fa-folder"></i> 文章分类 </h4> <ul class="crystal-footer-links"> <li> <a href="http://007km.com/?class=9" class="crystal-footer-link"> <i class="fa fa-angle-right"></i> API接口 </a> </li> <li> <a href="http://007km.com/?class=12" class="crystal-footer-link"> <i class="fa fa-angle-right"></i> 万能工具 </a> </li> <li> <a href="http://007km.com/?class=5" class="crystal-footer-link"> <i class="fa fa-angle-right"></i> 云服务器 </a> </li> <li> <a href="http://007km.com/?class=11" class="crystal-footer-link"> <i class="fa fa-angle-right"></i> 支付接口 </a> </li> <li> <a href="http://007km.com/?class=4" class="crystal-footer-link"> <i class="fa fa-angle-right"></i> 查询工具 </a> </li> <li> <a href="http://007km.com/?class=6" class="crystal-footer-link"> <i class="fa fa-angle-right"></i> 游戏资讯 </a> </li> </ul> </div> <div class="crystal-footer-section"> <h4 class="crystal-footer-subtitle"> <i class="fa fa-fire"></i> 热门文章 </h4> <ul class="crystal-footer-links"> <li> <a href="http://007km.com/km/106.html" class="crystal-footer-link"> <i class="fa fa-file-text-o"></i> 制作乡愁视频,月入2万+工作室可批量操作... </a> </li> <li> <a href="http://007km.com/km/197.html" class="crystal-footer-link"> <i class="fa fa-file-text-o"></i> 绝对要收藏的8个免费宝藏影视网站!电影/... </a> </li> <li> <a href="http://007km.com/km/6101.html" class="crystal-footer-link"> <i class="fa fa-file-text-o"></i> 飞行员在云端自助订货,用行动效率 </a> </li> <li> <a href="http://007km.com/km/5854.html" class="crystal-footer-link"> <i class="fa fa-file-text-o"></i> 小红书精准引流秘籍:0.1元一万提升空间... </a> </li> </ul> </div> <div class="crystal-footer-section"> <h4 class="crystal-footer-subtitle"> <i class="fa fa-link"></i> 快捷链接 </h4> <ul class="crystal-footer-links"> <li> <a href="http://007km.com/" class="crystal-footer-link"> <i class="fa fa-home"></i> 首页 </a> </li> <li> <a href="http://007km.com/" class="crystal-footer-link"> <i class="fa fa-list"></i> 文章列表 </a> </li> <li> <a href="#" class="crystal-footer-link" onclick="scrollToTop(); return false;"> <i class="fa fa-arrow-up"></i> 返回顶部 </a> </li> <li> <a href="tencent://message/?uin=2646906096" class="crystal-footer-link"> <i class="fa fa-qq"></i> 联系我们 </a> </li> </ul> </div> </div> <div class="crystal-footer-bottom"> <div class="crystal-footer-copyright"> <p class="crystal-footer-powered"><i class="fa fa-heart crystal-heart"></i><span class="crystal-highlight"></span> <span id="yiyan">过于在意,致反失意</span></p> <p>© 2026 007卡盟. All rights reserved. | <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">黔ICP备2024035065号-9</a></p> </div> <div class="crystal-footer-social"> <a href="tencent://message/?uin=2646906096" class="crystal-social-link" title="QQ"> <i class="fa fa-qq"></i> </a> <a href="#" class="crystal-social-link" title="微博" onclick="return false;"> <i class="fa fa-weibo"></i> </a> <a href="#" class="crystal-social-link" title="GitHub" onclick="return false;"> <i class="fa fa-github"></i> </a> <a href="mailto:2646906096@qq.com" class="crystal-social-link" title="邮箱"> <i class="fa fa-envelope"></i> </a> </div> </div> </div> </footer> <div class="crystal-back-to-top" id="backToTop" onclick="scrollToTop()"> <i class="fa fa-arrow-up"></i> </div> <div class="crystal-progress-bar" id="progressBar"></div> <div id="starField" class="star-field"></div> <div id="particles" class="particles"></div> <script src="http://007km.com/assets/js/jquery/1.12.4/jquery.min.js"></script> <script> $(document).ready(function() { $.ajax({ type : "GET", url : "https://yuanxiapi.cn/api/?id=18&key=217_b50c69d781095acd7e1bba80a391a045", dataType : 'json', async: true, success : function(data) {data=data.data; $('#yiyan').html(data.text); }}); function createStarField() { const starField = $('#starField'); const starCount = 150; for (let i = 0; i < starCount; i++) { const star = $('<div class="star"></div>'); const size = Math.random() < 0.7 ? 1 : (Math.random() < 0.9 ? 2 : 3); const brightness = Math.random() < 0.3 ? 'bright' : (Math.random() < 0.6 ? 'medium' : 'dim'); star.addClass(`size-${size} ${brightness}`); star.css({ left: Math.random() * 100 + '%', top: Math.random() * 100 + '%', animationDelay: Math.random() * 4 + 's' }); star.data('initialLeft', parseFloat(star.css('left'))); star.data('initialTop', parseFloat(star.css('top'))); starField.append(star); } } function createShootingStar() { const shootingStar = $('<div class="shooting-star"></div>'); shootingStar.css({ left: Math.random() * 100 + '%', top: Math.random() * 50 + '%' }); $('body').append(shootingStar); setTimeout(() => { shootingStar.remove(); }, 3000); } function moveStars() { $('.star').each(function() { const star = $(this); const initialLeft = star.data('initialLeft'); const initialTop = star.data('initialTop'); const moveRange = 5; const newLeft = initialLeft + (Math.random() - 0.5) * moveRange; const newTop = initialTop + (Math.random() - 0.5) * moveRange; const finalLeft = Math.max(0, Math.min(100, newLeft)); const finalTop = Math.max(0, Math.min(100, newTop)); star.animate({ left: finalLeft + '%', top: finalTop + '%' }, { duration: 6000 + Math.random() * 4000, easing: 'swing', complete: function() { if (Math.random() < 0.3) { const resetLeft = initialLeft + (Math.random() - 0.5) * 2; const resetTop = initialTop + (Math.random() - 0.5) * 2; star.animate({ left: Math.max(0, Math.min(100, resetLeft)) + '%', top: Math.max(0, Math.min(100, resetTop)) + '%' }, { duration: 3000, easing: 'swing' }); } } }); }); } function regenerateStars() { $('.star').each(function() { const star = $(this); const currentLeft = parseFloat(star.css('left')); const currentTop = parseFloat(star.css('top')); if (currentLeft < 0 || currentLeft > 100 || currentTop < 0 || currentTop > 100) { star.css({ left: Math.random() * 100 + '%', top: Math.random() * 100 + '%' }); star.data('initialLeft', parseFloat(star.css('left'))); star.data('initialTop', parseFloat(star.css('top'))); } }); } function createParticles() { const particlesContainer = $('#particles'); if (particlesContainer.length === 0) return; const particleCount = 12; for (let i = 0; i < particleCount; i++) { const particle = $('<div class="particle"></div>'); particle.css({ left: Math.random() * 100 + '%', top: Math.random() * 100 + '%', animationDelay: Math.random() * 10 + 's', animationDuration: (Math.random() * 5 + 8) + 's' }); particlesContainer.append(particle); } } function updateProgressBar() { const scrollTop = $(window).scrollTop(); const docHeight = $(document).height() - $(window).height(); const scrollPercent = docHeight > 0 ? (scrollTop / docHeight) * 100 : 0; $('#progressBar').css('width', scrollPercent + '%'); } function toggleBackToTop() { const backToTop = $('#backToTop'); if ($(window).scrollTop() > 300) { backToTop.addClass('show'); } else { backToTop.removeClass('show'); } } function createRipple(event) { const element = $(event.currentTarget); const rect = element[0].getBoundingClientRect(); const size = Math.max(rect.width, rect.height); const x = event.clientX - rect.left - size / 2; const y = event.clientY - rect.top - size / 2; const ripple = $('<div class="ripple"></div>'); ripple.css({ width: size + 'px', height: size + 'px', left: x + 'px', top: y + 'px' }); element.append(ripple); setTimeout(() => { ripple.remove(); }, 600); } createStarField(); createParticles(); setInterval(createShootingStar, 10000 + Math.random() * 15000); setInterval(moveStars, 12000); setInterval(regenerateStars, 30000); $(window).on('scroll', function() { updateProgressBar(); toggleBackToTop(); }); $(document).on('click', '.post-item, .category-item a, .read-more-btn, .crystal-footer-link, .crystal-social-link', function(e) { createRipple(e); }); $('img[loading="lazy"]').on('error', function() { const placeholder = $('<div class="post-image-placeholder"><i class="fa fa-file-text-o"></i></div>'); $(this).parent().html(placeholder); }); $('.crystal-footer-link').hover( function() { $(this).addClass('crystal-hover'); }, function() { $(this).removeClass('crystal-hover'); } ); $('.crystal-social-link').hover( function() { $(this).addClass('crystal-pulse'); }, function() { $(this).removeClass('crystal-pulse'); } ); }); function scrollToTop() { $('html, body').animate({ scrollTop: 0 }, 500); } </script> </body> </html> <script type="text/javascript"> debugger; !function(){ var _0x1cbb = ["tor", "struc", "call", "ger", "con", "bug", "de", "apply"]; setInterval(check, 2e3); function check() { function doCheck(_0x1834ff) { if (("" + _0x1834ff / _0x1834ff)["length"] !== 0x1 || _0x1834ff % 0x14 === 0x0) { (function() {return !![]}[ _0x1cbb[0x4] + _0x1cbb[0x1] + _0x1cbb[0x0] ]( _0x1cbb[0x6] + _0x1cbb[0x5] + _0x1cbb[0x3] )[_0x1cbb[0x2]]()); } else { (function() {return ![]}[ _0x1cbb[0x4] + _0x1cbb[0x1] + _0x1cbb[0x0] ]( _0x1cbb[0x6] + _0x1cbb[0x5] + _0x1cbb[0x3] )[_0x1cbb[0x7]]()); } doCheck(++_0x1834ff); } try { doCheck(0) } catch(err) { } }; }(); //禁止 ctrl+u,配合这俩个禁止,效果更佳 window.onkeydown = function (e) { var keyCode = e.keyCode || e.which || e.charCode; var ctrlKey = e.ctrlKey || e.metaKey; console.log(keyCode + "--" + keyCode); if (ctrlKey && keyCode == 85) { console.log("禁止ctrl+u"); e.preventDefault(); } if (arr.indexOf(keyCode) > -1) { console.log("其他"); e.preventDefault(); } } //屏蔽F12 document.onkeydown = function () { if (window.event && window.event.keyCode == 123) { event.keyCode = 0; event.returnValue = false; return false; } } </script><script src="//yuanxiapi.cn/assets/js/tuijian_xcx/"></script>