0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

みんなの株式からスクレイピングするとこうなる感じでしょう的な・・・。

Last updated at Posted at 2021-03-16

みんなの株式からスクレイピングするとこうなる感じでしょう的な・・・。
尚、コマンドラインから打ってください。

minkabu.php minkabu 9432

$argv[2]には銘柄コードが入ります。
※いまは機能するコードですが、みんなの株式のHTML構造が変われば取り出し方を変更する必要があります。

minkabu.php
<?php
if($argv[1]==="minkabu" && $argv[2]){
	$html = file_get_contents("https://minkabu.jp/stock/". $argv[2] ."/analysis");
	$dom = new DOMDocument();
	$html = mb_convert_encoding($html, "HTML-ENTITIES", 'UTF-8');
	@$dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
	$xpath = new DOMXPath($dom);
	$list = array(
	"//*[@id=\"layout\"]/div[2]/div[3]/div[2]/div/div[1]/div/div/div[1]/div[2]/div/div[2]/div",
	"//*[@id=\"contents\"]/div[3]/div[2]/div/div[3]/div[2]/div[1]/div[1]/div[2]/div[1]/div[2]/div/span",
	"//*[@id=\"contents\"]/div[3]/div[2]/div/div[3]/div[2]/div[1]/div[1]/div[2]/div[1]/div[1]/p",
	"//*[@id=\"contents\"]/div[3]/div[2]/div/div[3]/div[2]/div[1]/div[2]/div[2]/div[1]/div/span",
	"//*[@id=\"contents\"]/div[3]/div[2]/div/div[3]/div[2]/div[1]/div[2]/div[2]/div[3]/div/span"
	);

	$val = array();

	foreach ($list as $key => $value) {
		$val[$key] = $xpath->query($value)->item(0)->textContent;
	}
	print "株価:".preg_replace("/[ |\t|\n|\r|円]/","",$val[0]).PHP_EOL.
	"予想株価(個人)".$val[2].":".preg_replace("/[ |\t|\n|\r|円]/","",$val[1]).PHP_EOL.
	"買い:".$val[3].",売り:".$val[4].PHP_EOL;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?