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

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

$symbol = $argv[1];

$url = "".$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);

$dom = new DOMDocument();
$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 

Kommentar verfassen

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

Scroll to Top