Last active
December 12, 2016 15:06
-
-
Save katopz/c2b030761fde67cf854f1b3a733723c1 to your computer and use it in GitHub Desktop.
Get element inside svg by xpath or string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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