2

I am trying to extract JavaScript source code in a website such as https://stackoverflow.com/

  • First method, I tried document.scripts DOM API function. I got an array of HTMLElement Object. I also tried document.scripts[0].text, but it can not be printed.

  • Second method, I used Sources panel in of Chrome DevTools enter image description here. But this method can not extract JS source code automatically.

  • Third method, building a web scraper to extract <script> tag in website. However, this method can not extract the dynamic JS source code which can include by jquery load script, for example.

So, Are there any method to extract JavaScript source code in a website?

kha
  • 349
  • 3
  • 18
  • 1
    Do you have permission to use their source code? if so then just ask them for it, otherwise you're probably breaking all sorts of copyright and legal rules – Pete May 18 '17 at 09:09
  • did you try some kind of plugin like the following: https://chrome.google.com/webstore/detail/chrome-extension-source-v/jifpbeccnghkjeaalbbjmodiffmgedin – quirimmo May 18 '17 at 09:14
  • 2
    _“I also tried document.scripts[0].text, but it can not be printed.”_ – that will of course only work for script elements that have script code embedded between the opening and closing script tag. If the script was embedded via the `src` attribute of the script element however, you would need to look at that. – CBroe May 18 '17 at 09:17
  • @CBroe ...via the `src` attribute – hindmost May 18 '17 at 09:19
  • @CBroe If we can take advantage of the source code in Source panel is better since it already downloaded in browser. – kha May 18 '17 at 13:56
  • That source panel is part of dev tools. That is nothing you can easily hook into with JS that runs in the context of a website. "Save page as ..." could perhaps be a possibility, have you tried that? That at least stores all the external script files (together with the rest of the page assets.) – CBroe May 18 '17 at 14:58

0 Answers0