Skip to content

Fetches a selector of an html element, and shortens it with a genetic algorithm.

Notifications You must be signed in to change notification settings

csandven/Fetch-Selector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fetch-Selector

Fetches a selector of an html element, and shortens it with a genetic algorithm.

Installation

npm install --save fetch-selector

Usage

import fetchSelector from 'fetch-selector'

// Example element
const div = document.querySelector('#top > div._9dMXo.w-third-l.mt3.w-100.ph3.ph4-m.pv3.pv0-l.order-1-ns.order-0 > div:nth-child(8) > p > a')

// Return a default selector string from an element
// This selector is quite long, but the function is quicker
// than the shortened one
const longSelector = fetchSelector(div)
// returns: "#top div:nth-child(4) > div:nth-child(8) > p.n8Z-E > a.zE7yA"

const shortSelector = fetchSelector(div, true)
// returns: #top div:nth-child(4) div:nth-child(8) a.zE7yA"

About

Fetches a selector of an html element, and shortens it with a genetic algorithm.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published