matthewmueller / x-ray

The next web scraper. See through the <html> noise.
MIT License
5.88k stars 350 forks source link

How to get a variable from a script #196

Closed gragra100 closed 5 years ago

gragra100 commented 8 years ago

How can i get with x-ray a variable in a script tag ?

For example: <script type="text/javascript" charset="utf-8"> var dataFromServer = [{a:a},{b:b},{c:c},...,{n:n}] </script>

I need the variable "dataFromServer", is there a way to retrieve it?

bisubus commented 8 years ago

@gragra100 Have you tried to get script contents with script:not([src]) | someScriptFilter selector and then parse it in someScriptFilter with regexp? Obviously, it won't work if dataFromServer is something complex that cannot be fed to JSON.parse.

DroidNinja commented 7 years ago

How are you able to retrieve it? Any solution?

gragra100 commented 7 years ago

I used another package, I couldn't do it with x-ray

bisubus commented 7 years ago

@DroidNinja As it was mentioned above, you can reach raw DOM within filter functions. I used this hack to overcome some library limitations.

lathropd commented 5 years ago

For now, that’s the “correct” answer. Arbitrary JavaScript parsing is its in major thing. This is related to the longstanding issue #6.