1

In Python, I can retrieve Javascript from an HTML document using the following code.

import urllib2, jsbeautifier
from bs4 import BeautifulSoup

f = urllib2.urlopen("http://www.google.com.ph/")

soup = BeautifulSoup(f, "lxml")
script_raw = str(soup.script)

script_pretty = jsbeautifier.beautify(script_raw)
print(script_pretty)

But how about if the script comes from a Javascript file on the server, like:

<script src="some/directory/example.js" type="text/javascript">

Is it possible to retrieve "example.js"? If so, how?

Context: I'm examining the Javascript of phishing web pages.

  • If the target of ` – Seldom 'Where's Monica' Needy Oct 14 '16 at 05:22
  • In urllib use urlretrive here is an example http://stackoverflow.com/questions/257409/download-image-file-from-the-html-page-source-using-python – Hisham Karam Oct 14 '16 at 05:25

3 Answers3

1
<script src="some/directory/example.js" type="text/javascript">

the code above will get some/directory/example.js from server you just make folders and file structure follow the pattern above

Alongkorn
  • 3,968
  • 1
  • 24
  • 41
1

The easiest way is to right click on that page in your browser, choose page script, click on that .js link, and it will be there.

Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50
0

If you want to load at run time, like some part of your javascript is dependent on other javascript, then for loading javascript at run time, you can use require.js .

Tarun Khurana
  • 887
  • 8
  • 9