Words do not say more, the following directly to see implementation code.
The primary function has only one class implementation (stock.class.php):
<?php class stockclass{public $stockId;
Public function __construct ($stockId) {$this-> = $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
_replace ($result [0][$index], $this-> $fun ($html), $template); } return Mb_convert_encoding ($template, "GBK", "UTF-8"); Windows command prompt encoding is GBK} Private function Match ($pattern, $html, $itemIndex = 1) {$pattern = '/'. Str_replace ('/', ' \/', $pattern).
'/';
if (Preg_match ($pattern, $html, $result)) {return $result [$itemIndex];
}else{return "-"; }//Trend rules are the same, merging Private function Qushipattern ($name) {return ' <dIV class= "Txt-aside" >. $name.
': </div>\s*<div class= "Txt-main" > ([^<]*) </div> ';
}//Supported label private function name ($html) {return $this-> match ("<title> ([^\ (<]*) \ (", $html, 1); Private Function Score ($html) {return $this-> match (' <span class= ' analyze-num ' > \d+ (\.\d+)?)
</span> ', $html); Private Function Tips ($html) {return $this-> match (' <span class= ' analyze-tips ' > ([^<]*) </span> ', $h
TML);
The Private Function Qushishort ($html) {return $this-> match ($this-> qushipattern ("Short term trend"), $html);
The 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); }}?>
The calling 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}";//Rating
$temp. = "{tips}";//Description
$temp. = "{qushishort}";//short-term trend
$temp. = "{Qus Himiddle} "; Medium-term trend
$temp. = "{Qushilong}";//long-term trend
//$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 input too long, can be simplified by batch processing.
Save the following code as Stock.cmd.
@XXX \php.exe stock.php%1
Run Result:
This completes the collection of individual stock trends, and can be saved as a batch file if all stock information is to be collected (Batch.cmd)
@echo off, call, stock, 000001 call, 000002 call, 000003 call, Stock, 000004 call, Stock
000005
call-Stock 000006 call-000007-call-
stocks ticker 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 more responsible analysis.
The above is the use of PHP command-line mode to collect stock trend information of the entire content, this function is very convenient and practical, interested friends quickly practice it.