Some yahoo data is collected. I used to write similar things in my company. this time I wrote a simple collection program for my boss. Very simple .. Khan. No technical skills. Data source: c has previously written similar things in the company. this time, it helped previous superiors write a simple collection program.
Very simple .. Khan. No technical skills.
Data source: http://cn.finance.yahoo.co...
Demo address: http: // traffic02.100steps ....
(Added the data cache function .. Khan, I didn't use lite_cache. I wrote the simplest one myself ..)
The code is as follows:
Set_time_limit (0 );
$ Max_time = 3600;
Export cache_file='cache_yahoo.txt ';
$ Nowtime = time ();
If (! File_exists ($ cache_file )){
$ Filetime = 0;
} Else {
$ Filetime = filemtime ($ cache_file );
}
If ($ filetime + $ max_time <$ nowtime ){
// Update
Ob_start ();
Function get_yahoo_info ($ url ){
$ Content = file_get_contents ($ url );
$ Pattern = '|(.*)\((.*)\)(.*)| U ';
Preg_match_all ($ pattern, $ content, $ out );
$ Info ['company _ name'] = $ out [1] [0];
$ Info ['company _ stock'] = $ out [2] [0];
$ Pattern = '|Latest transaction price:(.*)| U ';
Preg_match_all ($ pattern, $ content, $ out );
$ Info ['stock _ price'] = $ out [1] [0];
$ Pattern = '|Ups and downs:(.*)| U ';
Preg_match_all ($ pattern, $ content, $ out );
$ Info ['stock _ uporlow'] = $ out [1] [0];
$ Pattern = '|Market value:(.*)| U ';
Preg_match_all ($ pattern, $ content, $ out );
$ Info ['stock _ value'] = $ out [1] [0];
Return $ info;
}
Using urls1_explode(',', file_get_contents('url.txt '));
$ I = 0;
$ Matchs = array ();
Foreach ($ urls as $ url ){
$ Rs = get_yahoo_info ($ url );
If (! Empty ($ rs )){
$ Matchs [$ I] = $ rs;
$ I ++;
$ Rs = '';
}
}
// Print_r (get_yahoo_info ('http: // cn.finance.yahoo.com/q? S = 000063. SZ '));
?>
|
Company name |
Stock code |
Stock price |
Stock increase |
Market value |
$ I = 1;Foreach ($ matchs as $ match ){?>
|
|
|
|
|
|
$ I ++;}?>
$ Content = ob_get_clean ();
$ Fp = fopen ($ cache_file, 'w ');
If (! $ Fp) echo 'failed to open the file ';
If (flock ($ fp, LOCK_EX) {// sort it to lock
If (! Fwrite ($ fp, $ content) echo 'file write failed ';
Flock ($ fp, LOCK_UN); // release lock
} Else {
// Echo "Couldn't lock the file! ";
If (! Fwrite ($ fp, $ content) echo 'file write failed ';
}
Fclose ($ fp );
// Echo 'cache time: '. time ();
Echo $ content;
} Else {
// Echo 'cache! ';
Echo file_get_contents ($ cache_file );
}
?>
Bytes. Very simple .. Khan. No technical skills. Data source: http: // c...