PHP獲取網頁的 Html源代碼輸出並執行


 

<?php $srcurl = "所要截取目標的URL地址"; $handle = fopen($srcurl,"rb"); $content = fread($handle,10240000); $start_position=strpos($content,'截取內容開始代碼A'); $start_position=$start_position+strlen('截取內容開始代碼A'); $end_position=strpos($content,' 截取內容結束代碼C'); $length=$end_position-$start_position; $content=substr($content,$start_position,$length); echo 'document.write("'.$content.'")'; ?>

這樣就可以截取所需的內容B。追后賦予$content,我在最后加上了echo ‘document.write為的是這樣就生成了JS代碼。 直接就成了JS代碼可直接在我想需要此內容的地方用JS調用顯示。

 

這個你用php是不能獲得的,它又不是通過get或post提交的 可以給你的<td>一個id,然后通過 document.getElementByIdx_x_x_x("name").innerHtml就可以獲得了

 
 

PHP 獲取指定網站、網頁、URL 的 <head> 標題:

獲取網頁的標題:

<? 
$url = 'http://www.baidu.com/'; 
$lines_array = file($url); 
$lines_string = implode('', $lines_array); 
eregi("<head>(.*)</head>", $lines_string, $head); 
echo $head[0]; 
?>

 
 

PHP 獲取網頁的 Html 源代碼輸出並執行:

獲取網頁Html源代碼輸出並執行1:

<?php
$lines = file('http://www.baidu.com/');
foreach ($lines as $line_num => $line) {
echo $line;
}
?>

獲取網頁Html源代碼輸出並執行2:

<?php
echo file_get_contents("http://www.baidu.com/");
?>

 

 

 

 

PHP 獲取指定網站、網頁、URL 的 Html 源代碼:

獲取網頁Html源代碼:

<?php
$lines = file('http://www.baidu.com/');
foreach ($lines as $line_num => $line) {
echo "Line <b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}
?>

特定網頁的特定代碼段

<?php 

$url = "http://finance.qq.com/a/20110428/005344.htm"; 

$contents = file_get_contents($url); 

//如果出現中文亂碼使用下面代碼 

//$getcontent = iconv("gb2312", "utf-8",$contents); 

//echo $contents; 

 

$from="<div id=\"Cnt-Main-Article-QQ\"><P style=\"TEXT-INDENT: 2em\">";

$end="</div>";

 

$q=cut($contents, $from, $end);

echo $q;

 

 

function cut($file,$from,$end){ 

 

$message=explode($from,$file); 

$message=explode($end,$message[1]); 

return $message[0]; 

 

 

 

?>

 

深圳勞務派遣公司

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM