Skip to content

Instantly share code, notes, and snippets.

@katopz
Last active December 12, 2016 15:06
Show Gist options
  • Save katopz/c2b030761fde67cf854f1b3a733723c1 to your computer and use it in GitHub Desktop.
Save katopz/c2b030761fde67cf854f1b3a733723c1 to your computer and use it in GitHub Desktop.
Get element inside svg by xpath or string
// By XPATH
// https://github.com/facebook/react/graphs/participation?h=28&type=sparkline&w=155
$x("//*[local-name() = 'polyline']/@points")[0].value.split(',')
// By String
fetch('https://github.com/facebook/react/graphs/participation?h=28&type=sparkline&w=155').then((res) => {
return (res.text())
}).then((text) => {
// x0, y0, x1, y1, ...
console.log(text.match(/points=\"(.*?)"/)[1].trim().split(' ').join(',').split(',').map(s => Number(s)))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment