手机版

利用服务器端编程语言(专业超文本预处理器的缩写)命令行模式采集股票趋势信息

时间:2021-09-07 来源:互联网 编辑:宝哥软件园 浏览:

话不多说,下面直接来看实现代码。

主要函数只有一个类实现(stock.class.php):

?服务器端编程语言(Professional Hypertext Preprocessor的缩写)类stock class { public $ stock id public function _ _ construct($ stock id){ $ this-stock id=$ stock id;}私有函数GetURl(){ return ' http://股龄。10 jqka。com。cn/' .$这个-斯托克Id .'/';}私有函数getpage(){ return file _ get _ contents($ this-GetURl());} //核心,通过正则匹配出标签名,并将对应的方法的结果替换掉标签占位符公共函数GetInfo($ template){ $ html=$ this-GetPage();if(preg_match_all('/\{([^\}]*)\}/',$template,$结果)){ foreach($ result[1]as $ index=$ fun){ $ template=str _ replace($ result[0][$ index],$this - $fun($html),$ template);} }返回mb_convert_encoding($template,' GBK ',' UTF-8 ');//Windows的命令提示符编码是GBK }私有函数匹配($pattern,$html,$itemIndex=1){ $pattern='/' .str _ replace(“/”、“\/”、$pattern).'/';if(preg_match($pattern,$html,$ result)){ return $ result[$ ItemIndex];} else { return '-';} } //趋势的规则都一样,合并私有函数qushiPattern($ name){ return ' div class=' txt-average ' ' .$name ./div \ s * div class='txt-main'([^]*)/div';} //支持的标签私有函数名($ html){ return $ this-match('title([^\(]*)\(',$ html,1);}私有函数score($ html){ return $ this-match(' span class=' analyze-num '(\ d(\).\d)?)/span ',$ html);}私有函数提示($ html){ return $ this-match(' span class='analyze-tips'([^]*)/span',$ html);}私有函数qushishort($ html){ return $ this-match($ this-qushiPattern('短期趋势),$ html);}私有函数qushimiddle($ html){ return $ this-match($ this-qushiPattern('中期趋势),$ html);}私有函数qushilong($ html){ return $ this-match($ this-qushiPattern('长期趋势),$ html);} }?命令提示符中的调用方法如下(stock.php):

?PHP if(count($ argv)=2){ require(' stock。上课。PHP’);$ stock id=$ argv[1];$ stock=新股票类别($ stock id);$ temp=$ stockId$temp .=" { name }//名称$temp .=" { score }//评分$temp .=" { tips }//描述$temp .=" { qushishort }//短期趋势$temp .=" { qushimiddle }//中期趋势$temp .=' { qushilong }//长期趋势//$temp=(紫定一}";//自定义,直接在StockClass增加紫定一方法即可$temp .=' \ ne CHO $ stock-Getinfo($ temp);}?直接使用* \ PHP。exe stock.php股票代码即可实现调用,每次输入太长的,可以用批处理简化。

将下面的代码保存为stock.cmd。

@ XXX \ PHP。exe stock.php % 1运行结果:

这样就完成了单个股票趋势的采集,如果要采集所有的股票信息,可以保存为批处理文件(batch.cmd)

@回声关闭股票000001call股票000002call股票000003call股票000004call股票00005呼叫股票000006呼叫股票000007呼叫股票股票代码n.双击打开即可显示,如果想保存到文件,可以执行batch.cmd log.txt,然后将结果复制到Execl(或ET)即可进行更负责的分析。

以上就是利用服务器端编程语言(专业超文本预处理器的缩写)命令行模式采集股票趋势信息的全部内容,这个功能很方便实用,感兴趣的朋友们快快实践起来吧。

版权声明:利用服务器端编程语言(专业超文本预处理器的缩写)命令行模式采集股票趋势信息是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。