用php curl xpath刮银价格

时间:2015-05-18 06:41:04

标签: php curl xpath scraper

    <?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";
}
?>

试图提高白银的价格,但不断得到一个空白页不确定它是否是一个https或者如果我得到错误的xpath任何帮助将非常感谢谢谢!

0 个答案:

没有答案