Guest User

Tampermonkey webscraper

a guest
Jan 14th, 2026
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Initial Price Tracker (indiscriminate)
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  Extracts Title, Price, and Link for spreadsheet analysis
  6. // @author       Gemini
  7. // @match        https://duckduckgo.com/*
  8. // @grant        GM_setClipboard
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     // 1. Create the UI Button
  15.     const btn = document.createElement("button");
  16.     btn.innerHTML = "📊 Copy Market Data";
  17.     btn.style = `
  18.         position: fixed; top: 100px; right: 20px; z-index: 99999;
  19.         padding: 12px 20px; background-color: #de5833; color: white;
  20.         border: none; border-radius: 8px; font-weight: bold;
  21.         cursor: pointer; box-shadow: 0 4px 6px rgba(0,0,0,0.2);
  22.     `;
  23.     document.body.appendChild(btn);
  24.  
  25.     btn.onclick = function() {
  26.         let count = 0;
  27.         let output = "Title\tPrice\tLink\n"; // Tab-separated header
  28.  
  29.         // 2. Select all list items
  30.         const listItems = document.querySelectorAll('li');
  31.  
  32.         listItems.forEach(li => {
  33.             // Find the anchor that has a title (The main product link)
  34.             const anchor = li.querySelector('a[title]');
  35.             // Find the price (Look for a span containing $)
  36.             const spans = Array.from(li.querySelectorAll('span'));
  37.             const priceSpan = spans.find(s => s.textContent.includes('$'));
  38.  
  39.             // 3. Validation Logic: Ensure it's a real listing
  40.             if (anchor && priceSpan) {
  41.                 const title = anchor.getAttribute('title').trim();
  42.                 const link = anchor.href;
  43.                 // Clean the price: Remove $, commas, and extra text (e.g., "$2,500.00 Free Shipping" -> "2500.00")
  44.                 const rawPrice = priceSpan.textContent;
  45.                 const cleanPrice = rawPrice.replace(/[^\d.]/g, '');
  46.  
  47.                 if (title && cleanPrice) {
  48.                     output += `${title}\t${cleanPrice}\t${link}\n`;
  49.                     count++;
  50.                 }
  51.             }
  52.         });
  53.  
  54.         // 4. Hand-off to Clipboard
  55.         if (count > 0) {
  56.             GM_setClipboard(output);
  57.             btn.innerHTML = `✅ Copied ${count} items!`;
  58.             btn.style.backgroundColor = "#4CAF50";
  59.             // Reset button color after 3 seconds
  60.             setTimeout(() => {
  61.                 btn.innerHTML = "📊 Copy Market Data";
  62.                 btn.style.backgroundColor = "#de5833";
  63.             }, 3000);
  64.         } else {
  65.             alert("No listings found. Try scrolling down to load more results.");
  66.         }
  67.     };
  68. })();
Tags: Webscraping
Advertisement
Add Comment
Please, Sign In to add comment