这是我的代码:
<?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);
使用此代码,我尝试解析网址并从包含GBP
的表格中获取该行,并从最后td
获取文本。
但是我的代码似乎无效。我的错误在哪里,我该如何解决?
答案 0 :(得分:0)
你为什么要用这条线?
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
除了说“我不关心安全,请破解我!”这是不正确的用法,应该设置为常量。请尝试使用现代安全协议:
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
你会有更好的运气。