开发者

How to find all javascript on page with php given url?

In php how would I grab all javascript from a pa开发者_JAVA技巧ge given it's url? Is there a good regular expression to get the src of all javascript script tags or the script inside of them?


You can use PHP Simple HTML DOM to traverse the DOM for <script> tags. You can grab inline scripts directly in a string and get the src attribute for externally linked scripts and download them directly with curl or something. It would require some coding, I don't know if there is a 'magic' script that would do that automatically for you.


This should place the values of all src attributes contained in script tags into an array in the variable $matches. Check out the documentation for the format of the the array, as there is another parameter that will allow you to modify it.

preg_match_all('/<script[^>]*src=[\'"]([^\'"])+[\'"]/', $string, $matches);


I would suggest htmlSQL.

http://www.jonasjohn.de/lab/htmlsql.htm

With that you can get the code with tags as well as inline javascript for onclick like events also.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜