如何检索脚本标记源内容?

时间:2013-10-24 19:22:59

标签: php html html-parsing simpledom

我的代码有一个小问题..我访问了脚本标签中的src值,以获取在服务器端找到的JavaScript页面的内容。这是好的,因为我得到了我想要的但是问题是,我也得到了HTML代码..我不想要HTML代码。以下是我的所作所为。请帮忙吗?

     <?php
    //simple_html_dom.php caters for malformed html
    include('simple_html_dom.php');  
    $html = new simple_html_dom();  

    //load the All code file 
    $html->load_file("test.txt");

    $file = fopen("externalScript.txt","w");

    $Script=$html->find("script");

    $temp="";
    $url="http://www.xyz.com";
    foreach($Script AS $Spt){
        $src=$Spt->src;
        //check if the script src has "http://" prefix
        if(strpos($src,'http://')!==0){
            $src=$url."/".$src;
        }
        $get_script=file_get_contents($src);

        $temp.=$get_script.PHP_EOL; 
    }
    fwrite($file,($temp));
    fclose($file);
?>

0 个答案:

没有答案