脚本宝典收集整理的这篇文章主要介绍了利用PHP命令行模式采集股票趋势信息,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
话不多说,下面直接来看实现代码。
public function __construct($stockId){
$this -> stockId = $stockId;
}
private function getUrl(){
return "http://stockpage.10jqka.com.cn/" . $this -> stockId . "/";
}
private function getPage(){
return file_get_contents($this -> getUrl());
}
//核心,通过正则匹配出 标签名,并将对应的方法的结果替换掉标签占位符
public function getInfo($template){
$htML = $this -> getPage();
if( preg_match_all("/{([^}]*)}/",$template,$result) ){
foreach($result[1] as $index => $fun){
$template = str_replace($result[0][$index],$this -> $fun($html),$template);
}
}
return mb_convert_encoding($template,"GBK","UTF-8"); //Windows的命令提示符编码是GBK
}
private function match($pattern,$html,$ITemIndex = 1){
$pattern = '/' . str_replace('/','\/',$pattern) . '/';
if( preg_match($pattern,$result) ){
return $result[$itemIndex];
}else{
return "-";
}
}
//趋势的规则都一样,合并
private function qushiPattern($name){
return '<div class="txt-aside">' . $name . ':
以上是脚本宝典为你收集整理的利用PHP命令行模式采集股票趋势信息全部内容,希望文章能够帮你解决利用PHP命令行模式采集股票趋势信息所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。