PHP code example of yidas / tw-stock-crawler
1. Go to this page and download the library: Download yidas/tw-stock-crawler library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yidas / tw-stock-crawler example snippets
use yidas\twStockCrawler\Crawler;
$parser = \yidas\twStockCrawler\Crawler::config(["source"=>"twse"]);
$parser::setStockId("2330");
$priceData2330 = $parser::getLastPrice();
$priceData2454 = $parser::getLastPrice("2454");
$companyData2330 = $parser::getCompanyData();
Array
(
[id] => 2330
[isOTC] =>
[title] => 台積電
[industry] => 半導體
)
Array
(
[date] => 20210517
[timestamp] => 13:30:00
[amount] => 549
)
Array
(
[0] => Array
(
[year] => 2020
[amount] => 19.98
[details] => Array
(
[0] => Array
(
[year] => 2020
[belong] => Q4
[amount] => 5.51
)
[1] => Array
(
[year] => 2020
[belong] => Q3
[amount] => 5.3
)
[2] => Array
(
[year] => 2020
[belong] => Q2
[amount] => 4.66
)
[3] => Array
(
[year] => 2020
[belong] => Q1
[amount] => 4.51
)
)
)
)
Array
(
[year] => 2009
[cash] => 26
[stock] => 0.02
[total] => 26.02
[details] => Array
(
[0] => Array
(
[year] => 2009
[belong] => 2009
[cash] => 26
[cashReleaseYear] => 2010
[cashReleaseDate] => 2010/08/26
[stock] => 0.02
[stockReleaseYear] =>
[stockReleaseDate] => 2010/08/26
[total] => 26.02
)
)
)
Array
(
[year] => 2019
[cash] => 8.16
[stock] => 0
[total] => 8.16
[details] => Array
(
[0] => Array
(
[year] => 2019
[belong] => H2
[cash] => 4.16
[cashReleaseYear] => 2020
[cashReleaseDate] => 2020/09/29
[stock] =>
[stockReleaseYear] =>
[stockReleaseDate] =>
[total] => 4.16
)
[1] => Array
(
[year] => 2019
[belong] => H1
[cash] => 4
[cashReleaseYear] => 2020
[cashReleaseDate] => 2020/04/20
[stock] =>
[stockReleaseYear] =>
[stockReleaseDate] =>
[total] => 4
)
)
)
Array
(
[year] => 2020
[cash] => 10
[stock] => 0
[total] => 10
[details] => Array
(
[0] => Array
(
[year] => 2020
[belong] => Q4
[cash] => 2.5
[cashReleaseYear] => 2021
[cashReleaseDate] => 2021/07/14
[stock] =>
[stockReleaseYear] =>
[stockReleaseDate] =>
[total] => 2.5
)
[1] => Array
(
[year] => 2020
[belong] => Q3
[cash] => 2.5
[cashReleaseYear] => 2021
[cashReleaseDate] => 2021/04/14
[stock] =>
[stockReleaseYear] =>
[stockReleaseDate] =>
[total] => 2.5
)
[2] => Array
(
[year] => 2020
[belong] => Q2
[cash] => 2.5
[cashReleaseYear] => 2021
[cashReleaseDate] => 2021/01/13
[stock] =>
[stockReleaseYear] =>
[stockReleaseDate] =>
[total] => 2.5
)
[3] => Array
(
[year] => 2020
[belong] => Q1
[cash] => 2.5
[cashReleaseYear] => 2020
[cashReleaseDate] => 2020/10/14
[stock] =>
[stockReleaseYear] =>
[stockReleaseDate] =>
[total] => 2.5
)
)
)