Js2Py icon indicating copy to clipboard operation
Js2Py copied to clipboard

Js2Py 'document is not defined' and I don't need 'document' at all

Open ElJaviLuki opened this issue 4 years ago • 6 comments

I scraped a server-side dynamically-obfuscated JS script from a main page and wanted to get some specific data from it (by evaluating some of the obfuscated script expressions). Although there are lots of occurrences of document and similar references to DOM, the part I'm interested in is not DOM dependent. So is there any way to ignore document is not defined or any other workaround on it?

Thanks!

ElJaviLuki avatar Mar 22 '21 10:03 ElJaviLuki

You have to write minimal implementations of the objects and functions called by your target code and make sure your code runs first. I did it by creating a context, running my code, and then each html code block separately. This way it could fail on ad code while still allowing me process the bits of the code I'm interested in, pulling the results from the context afterwards. DOM manipulation can be a real pain if you need it though.

worstperson avatar Mar 22 '21 17:03 worstperson

Please, can you provide a short example? I don't get your point. Thanks :)

ElJaviLuki avatar Mar 22 '21 23:03 ElJaviLuki

If you would please provide some example code, I can provide an example of how it can be executed.

worstperson avatar Mar 24 '21 16:03 worstperson

If you would please provide some example code, I can provide an example of how it can be executed.

Okay @worstperson , so this code is server-side dynamically obfuscated so I cannot reduce it since I would end up ignoring essential parts for data evaluation.

Ctrl+F and search for var q = h[bo('0x149')](['.'], j)[bo('0xf9')](''). I would like Python to evaluate and get the value of j after executing this line and save it into a str (String). Once done, the script can be stopped with no problem. The process per se of getting j is not DOM dependent at all, but obviously you can see lots of occurrences of symbols inside DOM.

Click HERE to see the JS code

ElJaviLuki avatar Mar 25 '21 18:03 ElJaviLuki

I finally ended up using Jsdom in node.js to scrape the needed data.

ElJaviLuki avatar Mar 27 '21 12:03 ElJaviLuki

@ElJaviLuki How did you solve it with Jsdom and nodejs ? I'm trying to figuring out which versions work. Thanks.

anmaped avatar Jul 15 '22 13:07 anmaped