Greasy Fork is available in English.

MagicScraper

Scrapes and displays data from the web page based on rules.

لا ينبغي أن لا يتم تثبيت هذا السكريت مباشرة. هو مكتبة لسكبتات لتشمل مع التوجيه الفوقية // @require https://update.greasyfork.org/scripts/471264/1222840/MagicScraper.js

المؤلف
aolko
الإصدار
0.1
تم إنشاؤه
20-07-2023
تم تحديثه
20-07-2023
الترخيص
لا يوجد

Define your rules object (either inline or external)

const rules = {
  // Your rules object here
};

Define the options

const options = {
  keepChildren: false, // Set to true if you want to retain children of scraped elements
};

Call the scraper function with the rules object or the external URL.

magicScraper(rules, [options]);
// OR
magicScraper('https://example.com/rules.json', [options]);

Rules definition

const rules = {
  // Global rules for the entire example.com domain
  'example.com': {
    title: 'h1',
    content: '.main-content',
    pages: {
      // Specific rules for the homepage of example.com
      '/': {
        subtitle: '.subtitle',
        featuredImage: '.featured-image',
      },
      // Fallback rules for any other page under example.com
      '*': {
        defaultTitle: 'h2',
      },
    },
      // Specific rules for any page under the blog subdomain
      'blog.example.com/*': {
        blogTitle: '.blog-title',
        blogContent: '.blog-content',
      },
      // Wildcard rules for any subdomain under example.com
      '*.example.com': {
        subdomainTitle: '.subdomain-title',
      },
      // Wildcard rules for any page under the about subdomain
      'about.example.com/*': {
        aboutSection: '.about-section',
      }
  },
  // Global rules for the entire test.com domain
  'test.com': {
    title: 'h1',
    testContent: '.test-content',
  },
  // Fallback rules for any other domain not specified above
  '*': {
    defaultTitle: 'h1',
    defaultContent: '.main-content',
  },
};