// ==UserScript== // @name 获取搜索引擎结果 // @namespace http://tampermonkey.net/ // @version 1.1 // @description 自动获取搜索引擎结果,包括标题、链接和描述 // @author YourName // @match https://www.google.com/search* // @match https://www.bing.com/search* // @grant none // ==/UserScript== (function() { 'use strict'; // 根据当前域名选择对应的解析逻辑 const hostname = location.hostname; let results = []; if (/\.google\..*/.test(hostname)) { // Google 搜索结果选择器 results = Array.from(document.querySelectorAll('div#search div.g')).map(item => ({ title: item.querySelector('h3')?.innerText || '', link: item.querySelector('a')?.href || '', description: item.querySelector('div[data-snf=nke7rc]')?.innerText || '' })); } else if (/bing\.com/.test(hostname)) { // Bing 搜索结果选择器 results = Array.from(document.querySelectorAll('.b_algo')).map(item => ({ title: item.querySelector('h2 a')?.innerText || '', link: item.querySelector('h2 a')?.href || '', description: item.querySelector('.b_caption p')?.innerText || '' })); } // 打印到控制台 console.log('搜索结果:', results); // 也可以在页面显示结果 const resultDiv = document.createElement('div'); resultDiv.style.position = 'fixed'; resultDiv.style.top = '10px'; resultDiv.style.right = '10px'; resultDiv.style.backgroundColor = '#fff'; resultDiv.style.border = '1px solid #ccc'; resultDiv.style.padding = '10px'; resultDiv.style.maxHeight = '400px'; resultDiv.style.overflow = 'auto'; resultDiv.style.zIndex = '9999'; resultDiv.innerHTML = '

搜索结果:

' + results.map(r => `
${r.title}

${r.description}

`).join(''); document.body.appendChild(resultDiv); })();