Here is my code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = 'https://www.fibank.bg/bg/valutni-kursove/page/461';
$curl = curl_init();
curl_setopt($curl, CURLOPT_COOKIE, "ChosenSite=www; SportsDirect_AnonymousUserCurrency=GBP; language=en-GB");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($curl, CURLOPT_VERBOSE, true);
$str = curl_exec($curl);
curl_close($curl);
libxml_use_internal_errors(true);
$doc = new \DOMDocument();
$doc->loadHTML($str);
$xpath = new \DOMXpath($doc);
$value = $xpath->query('//td[em="GBP"]/parent::tr/td[last()]')->item(0)->nodeValue;
print_r($value);
With this code I am trying to parse the URL and get the line from the table which contains GBP
and the get the text from the last td
.
However my code seems to be not working. Where is my mistake and how can I fix it?