从外部网站获取所有脚本 [英] Get all scripts from external website
问题描述
我在这里有一些代码,使用此代码可以渲染外部页面(类似于iframe),但是我有源代码.但是,当我启动代码时,一切都很好,但是在那里显示了一个窗口,我无法关闭它来查看内容.这是代码: 代码:
I have a some code here and I with this code render external page (similar to iframe) but I got a source code. But when I start my code all is good but one window is showing there and I can't to close his to see contents. Here is the code: Code:
<?php
$url = 'http://www.kupime.com/';
$data = file_get_contents($url);
$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;
echo $data;
?>
这会生成一个不错的HTML页面,但要关闭窗口,我还需要获取带有此书签的所有脚本
and this generate a good HTML page but to close window I need also to get all scripts with this bookmarklet
javascript: (function(){
s = document.getElementsByTagName('SCRIPT');
tx = '';
sr = [];
for (i = 0; i < s.length; i++) {
with (s.item(i)) {
t = text;
if (t) {
tx += t;
}
else {
sr.push(src)
};
}
};
with (window.open()) {
document.write('<textarea%20id="t">' + (sr.join("\n")) + "\n\n-----\n\n" + tx + '</textarea><script%20src="http://jsbeautifier.org/beautify.js"></script><script>with(document.getElementById("t")){value=js_beautify(value);with(style){width="99%";height="99%";borderStyle="none";}};</script>');
document.close();
}
})();
但是如何在上面的代码中实现呢?这是第一个(仅PHP代码)的演示 http://www.pluspon.com/get1.php 还是用一些wget来做到这一点?
But how can I implement this in my code above? Here is the demo of first (only php code) http://www.pluspon.com/get1.php or maybe to do this with some wget?
推荐答案
hack方式:如果您只想摆脱窗口,则只需添加隐藏该window元素的css.
hack way : if you just want to get rid of the window, you just need to add css that hide that window element.
<style>
#home_banner_campaign_wrapper,#active_banner_wrap {display:none;}
</style>
by,umm ..也许是这样的:
by, umm..perhaps like this :
<?php
$url = 'http://www.kupime.com/';
$data = file_get_contents($url);
$style = '<style>#home_banner_campaign_wrapper,#active_banner_wrap {display:none;}</style>';
//insert the style just before the closing head tag
$data = str_replace('</head>', $style.'</head>', $data);
$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;
echo $data;
?>
如果这种方法太愚蠢,请原谅我.
well pardon me if this way is too stupid..
这篇关于从外部网站获取所有脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!