开发者

How do you extract the javaScript code from a webpage?

I've to 开发者_如何学Pythonrefactor a bunch of html files containing a mix of html and javascript code. I'd like to isolate the javascript code to be able to use various tools (for instance gjslint).

Is there a tool to do that automatically ? (I did search but wasn't able to find anything, maybe using the wrong terms.)

thanks...


If you want to get the javascript with javascript you can use jQuery like so

$('script').each(function(){ 
    alert($(this).html()) 
});


WebDeveloperToolbar plugin to Firefox has an option Information->View Javascript that will list all inline scirpts and all included scripts and here you can cut and paste what you need.

It will all be presented as a single webpage with collapsable section for each scripttag and external file.

But eventhandlers like <a href"" onclick=""> will not be listed unfortunatly.

This also works on any webpage without having to edit them first.


If you install firebug there is a tab called "script" which displays the content of all files with JavaScripts.

EDIT: Just realized that it won't help you much if the scripts are inline. If it's included from various other files, it's still useful though.


Depends on the editor you're using, but you could do a RegularExpression search and extract blocks of text in the HTML/JS mix that is enclosed in <script></script> tags.


If you want to extract only the tags then you can try it with this site: https://js-download.com/

Here are the tags extracted and the result will be merged to one file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜