0
我试图从一个网站拉跨班级到另一个,但似乎无法使其工作。是否可以使用curl从不同网站获取单个单词?从另一个网站拉
什么是span类的正确语法?我的代码我收到警告:
Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/uptickgather.php on line 25
我的代码:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://quotes.wsj.com/UEPS');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
libxml_use_internal_errors(true);
$html = curl_exec($ch); // the whole document (in string) goes in here
$dom = new DOMDocument();
$dom->loadHTML($html); // load it
libxml_clear_errors();
$xpath = new DOMXpath($dom);
$class = $xpath->query('//[@class="cr_info info_price price_l"]//');
echo $class->nodeValue . ' ';
?>
第25行是:
echo $class->nodeValue . ' ';
到目前为止,我已经试图改变查询的格式工作用@语法。因此,我试图用一个斜杠,但据我了解,双斜杠将显示名称为所有属性
"cr_info info_price price_l"
我也尝试使用以下命令:
$class = $xpath->query('//[@class="cr_info info_price price_l"]//');
不过,我似乎无法使其工作。有没有人在xpath/curl有更多的经验对如何解决这个问题有任何建议?
编辑:当我使用VAR倾倒,它看起来像:
object(DOMNodeList)#3 (1) { ["length"]=> int(0) }
但我试图重新进入编码,和我完全丧失。谁能帮忙?
那么,是第25行? DOMDocument对象或CURL对象是否导致错误?你到目前为止尝试过哪些调试策略? – WillardSolutions
它应该回显什么?让我知道我会帮你取消这个HTML – meda
它应该回应股票的价格。 – user3517904