Yahoo Finance – Parse stock name

How to parse the stock name in Yahoo Finance?

Yahoo Finance Script

This script will open a web request to the Yahoo Finance Server. After that it searches for the element, which includes the full stock name.

mattionline:/home/stock# cat fetchname.php
<?php

if($argv[1] != "") {

$symbol = $argv[1];

$url = "https://de.finance.yahoo.com/quote/".$symbol;

$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
@$dom->loadHTML($html);
$link = $dom->getElementById('quote-header-info');
$test = explode("(", $link->textContent);
$name = $test[0];

echo $name;

}

?>

Execution of the programm

The parameter of the script is just the short symbol from Yahoo Finance to open the URL.

The output of the script is the full stock name.

You can edit the getElementById command to fetch other values like some fundamental stock data, historic prices or whatever….

mattionline:/home/stock# php -f fetchname.php CALN.SW
Calida Holding AG 
mattionline:/home/stock# php -f fetchname.php FRE.F
Fresenius SE & Co. KGaA 
mattionline:/home/stock#

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Nach oben scrollen