-2

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?

miken32
  • 42,008
  • 16
  • 111
  • 154
Venelin
  • 2,905
  • 7
  • 53
  • 117

1 Answers1

0

Why are you using this line?

curl_setopt($curl, CURLOPT_SSLVERSION, 3);

In addition to saying, "I don't care about security, please hack me!" this is incorrect usage and should be set to a constant. Try using a modern security protocol instead:

curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);

You will have much better luck.

miken32
  • 42,008
  • 16
  • 111
  • 154