Not much to say, the following directly see 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, the label name is matched by a regular match, and the result of the corresponding method is replaced 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_r Eplace ($result [0][$index], $this-$fun ($html), $template); }} return Mb_convert_encoding ($template, "GBK", "UTF-8"); The command prompt encoding 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 rules for the trend are all the same, merging the private function Qushipattern ($name) {return '. $name. ': \s* ([^<]*) '; }//support for tagged private function name ($html) {return $this, match (" <title>([^\ (<]*) \ (", $html, 1);} Private Function Score ($html) {return $this, match ('</title>(\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 Functi On Qushimiddle ($html) {return $this, match ($this-Qushipattern ("Medium trend"), $html), Private function Qushilong ($h tml) {return $this, match ($this-Qushipattern ("long-term trend"), $html);}? >
The invocation 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-term trend $temp. = "{Qushilong}"; Long-term trends//$temp. = "{Zidingyi}"; Custom, add Zidingyi method directly in Stockclass to $temp. = "\ n"; Echo $stock-GetInfo ($temp); }?>
Use the *\php.exe stock.php
stock code directly to implement the call, each time the input is too long, can be simplified with batch processing.
Save the following code as Stock.cmd.
@XXX \php.exe stock.php%1
Operation Result:
This completes the acquisition of a single stock trend, which can be saved as a batch file (Batch.cmd) If all stock information is to be collected
@echo Offcall stock 000001call stock 000002call stock 000003call stock 000004call stock 000005call stock 000006call stock 000007call stock stock Code N ...
Double-click to open to display, if you want to save to a file, you can execute batch.cmd > log.txt
, and then copy the results to EXECL (or ET) for a more responsible analysis.
The above is the use of PHP command line mode to collect the entire content of stock trend information, this function is very convenient and practical, interested friends quickly practice it.