PDA

View Full Version : Anh em cho mình hỏi



hoathach
08-01-2010, 17:32
Làm sao lấy kết quả giao dịch chứng khoán từ một trang khác cập nhật vào trang của mình.
Ví dụ:

VN-Index: 520.9 -12.44 (2.38%)Tổng KLGD:84,715,300 Tổng GTGD:3,884.84 tỷ VNĐ

Các anh em biết thì chỉ giúp mình nhé

danthanh.aweb
08-01-2010, 20:47
function StockInfo()
{

$htmlCode = "";
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
$linkget = "http://vnexpress.net/User/ck/Source/GetHCMSDataSmall.asp";
$html = html_get($linkget, $userAgent);

preg_match_all('#<tr[^>]*>(.*?)</tr[^>]*>#is', $html, $matches, PREG_PATTERN_ORDER);
$i = 0;
foreach($matches[1] as $rows)
{
preg_match_all('#<td[^>]*>(.*?)</td[^>]*>#is', $rows, $value, PREG_PATTERN_ORDER);
$GLOBALS["MCK"] = $value[1][0];
$GLOBALS["TC"] = $value[1][1];
$GLOBALS["GKL"] = $value[1][2];
$GLOBALS["KLGD"] = (int)$value[1][3];
$GLOBALS["TG"] = $value[1][4];

if((float)$GLOBALS["TG"] > 0)
{
$GLOBALS["CLGD"] = "ckblue";
}
elseif((float)$GLOBALS["TG"] < 0)
{
$GLOBALS["CLGD"] = "ckred";
}
else
{
$GLOBALS["CLGD"] = "ckyellow";
}

$htmlCode .= $GLOBALS['HOME_CLASS_TEMPLATE']->GetSnippet("StockInfo");

$i++;
if($i==50)
{
break;
}
}

echo $htmlCode;
die();
}

function html_get($link, $userAgent)
{
if (function_exists('curl_init') && $GLOBALS['AppPath']=="")
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
}else
{
$html = file_get_contents($link);
}
return $html;
}

Mình mới viết cho thằng http://glory.com.vn. Bạn sửa lại một tí là dùng được.

hoathach
09-01-2010, 08:53
Ý mình là thế này,dưới bản đồ chứng khoán thường có các kết quả giao dịch giống như trang http://www.rose.com.vn/
Mình ko biết lấy sao cho đúng