Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用php来提高银价_Php_Curl_Xpath_Scraper - Fatal编程技术网

用php来提高银价

用php来提高银价,php,curl,xpath,scraper,Php,Curl,Xpath,Scraper,试图拉银的价格,但不断得到一个空白页不知道它的原因是一个https或如果我得到了错误的xpath任何帮助将不胜感激谢谢 查看是否先加载页面。如果未加载,则错误不在Xpath中,而是在Curl中,大多数情况下,在使用带有ssl/HTTPS的URL时,需要关闭ssl变量,将此添加到Curl选项Curl\u setopt($Curl,CURLOPT\u ssl\u VERIFYPEER,false)页面仍然是空白的:/i我使用了不同的网站来删除银价,它似乎起了作用:) <?php $cu

试图拉银的价格,但不断得到一个空白页不知道它的原因是一个https或如果我得到了错误的xpath任何帮助将不胜感激谢谢

查看是否先加载页面。如果未加载,则错误不在Xpath中,而是在Curl中,大多数情况下,在使用带有ssl/HTTPS的URL时,需要关闭ssl变量,将此添加到Curl选项
Curl\u setopt($Curl,CURLOPT\u ssl\u VERIFYPEER,false)页面仍然是空白的:/i我使用了不同的网站来删除银价,它似乎起了作用:)
    <?php
$curl = curl_init('https://silvergoldbull.com/');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
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');

$page = curl_exec($curl);

if(!empty($curl)){ //if any html is actually returned

$pokemon_doc = new DOMDocument;
libxml_use_internal_errors(true);
$pokemon_doc->loadHTML($page);
libxml_clear_errors(); //remove errors for yucky html

$pokemon_xpath = new DOMXPath($pokemon_doc);

$silverprice = $pokemon_xpath->evaluate('string(/html/body/nav/div[3]/div/div/ul/li[1]/a/span/div/div/strong)'); //
echo $silverprice;
}
else {
    print "Not found";
}
?>