luochangzhi 发表于 2013-2-7 01:44:34

php用get_file_content函数获取黄金原油美指道琼斯等行情

下面是php用get_file_content函数获取黄金原油美指道琼斯等行情
其实就是php小偷抓取程序,这里用了php的et_file_content()函数抓取了别人页面的内容,其实也可以用fopen(),fsockopen(),curl等实现,有时间再写下这几个函数的用法。
完整代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>黄金资讯</title><script type="text/javascript" src="http://go24k.com/js/settab.js"></script><script language="javascript"></script> <!--<link href="static/master.css" rel="stylesheet" type="text/css">--><link href="http://go24k.com/templets/indexdiv/css/master.css" rel="stylesheet" type="text/css"></head><body><!--右边行情--><div class="r270">    <?php//header('Content-Type: text/html;charset=utf8');//需要采集的url地址$url = 'http://go24k.com/';$contents = file_get_contents($url);//$contents = iconv('gbk', 'utf-8', $contents); 编码转化//截取我们真正用到的 html代码块//从哪个位置开始截取$start = strpos($contents, '<div class="trends">');$contents = substr($contents, $start);//echo $contents;//从哪个位置结束$end= strpos($contents,'<div class="newslist">');$contents = substr($contents,0, $end);echo $contents;?></div><!--end 右边行情--></body></html>
演示地址:http://www.jianzhandiy.com/demo/hangqing.php
页: [1]
查看完整版本: php用get_file_content函数获取黄金原油美指道琼斯等行情