This article describes a simple stock acquisition tool, which collects the stock trend information of the same flush, and uses the php command line mode to write. Only some of the collection functions are completed, and the output data is copied to execl (or ET) for analysis, which is more convenient than any background. Next we will study it together. Let's just talk about the implementation code.
The main function has only one class implementation (stock. class. php ):
<? Php class StockClass {public $ stockId; 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 ();} // core, use regular expressions to match the tag name, replace the result of the corresponding method with the label placeholder 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 "); // the command prompt code for Windows is GBK} private function match ($ pattern, $ html, $ itemIndex = 1) {$ pattern = '/'. str_replace ('/', '\/', $ pattern ). '/'; if (preg_match ($ pattern, $ html, $ result) {return $ result [$ itemIndex];} else {return "-";}} // The trend rules are the same, and the private function qushiPattern ($ name) {return 'is merged''. $ Name .':
\ S *([^ <] *)
';} // The supported label private function name ($ html) {return $ this-> match ("([^ \ (<] *) \ (", $ Html, 1);} private function score ($ html) {return $ this-> match ('(\ d + (\. \ d + )?) ', $ Html);} private function tips ($ html) {return $ this-> match (' ([^ <] *) ', $ html );} private function qushishort ($ html) {return $ this-> match ($ this-> qushiPattern ("short-term trend"), $ html);} private function qushimiddle ($ html) {return $ this-> match ($ this-> qushiPattern ("medium-term trend"), $ html);} private function qushilong ($ html) {return $ this-> match ($ this-> qushiPattern ("long-term trend"), $ html) ;}}?> </Pre> </p>The call method in the command prompt is as follows (stock. php ):
<? Php if (count ($ argv)> = 2) {require ("stock. class. php "); $ stockId = $ argv [1]; $ stock = new StockClass ($ stockId); $ temp = $ stockId; $ temp. = "{name}"; // name $ temp. = "{score}"; // score $ temp. = "{tips}"; // description $ temp. = "{qushishort}"; // short-term trend $ temp. = "{qushimiddle}"; // medium trend $ temp. = "{qushilong}"; // long-term trend // $ temp. = "{zidingyi}"; // custom, add the zidingyi method directly in StockClass to $ temp. = "\ n"; echo $ stock-> getInfo ($ Temp) ;}?>
Direct use *\php.exe stock.php
The stock code can be called. each input is too long and can be simplified using batch processing.
Save the following code as stock. cmd.
@XXX\php.exe stock.php %1
Running result:
This completes the collection of individual stock trends. if you want to collect all stock information, you can save it as a batch processing file (batch. cmd)
@ Echo offcall stock 000001 call stock 000002 call stock 000003 call stock 000004 call stock 000005 call stock 000006 call stock 000007 call stock code n...
Double-click it to display it. to save it to a file, runbatch.cmd > log.txt
And then copy the results to Execl (or ET) for more responsible analysis.
The above is the use of PHP command line mode to collect all the content of the stock trend information, this function is very convenient and practical, interested friends to practice it quickly.