// ==UserScript== // @name 获取搜索引擎结果 // @namespace http://tampermonkey.net/ // @version 1.0 // @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 (hostname.includes('google.com')) { // Google 搜索结果选择器 results = Array.from(document.querySelectorAll('div.g')).map(item => ({ title: item.querySelector('h3')?.innerText || '', link: item.querySelector('a')?.href || '', description: item.querySelector('.IsZvec')?.innerText || '' })); } else if (hostname.includes('bing.com')) { // 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); })();