这是我用来提取数据的代码:
ini_set("user_agent","Opera/9.80 (Windows NT 6.1; U; Edition Campaign 21; en-GB) Presto/2.7.62 Version/11.00");
$html14=file_get_html("https://www.gamesrocket.com/battlefield-1.html");
$title14 = $html14->find('span.price',0)->children(0)->plaintext;
for ($i=0; $i <sizeof($title14) ; $i++) {
# code...
if($title14[$i]){
echo $title14[$i]->plaintext;
$a13=$title14[$i]->plaintext;
}
else{
echo "problem";
}
}
这里我试图从给定页面中提取价格,但我收到此错误:Trying to get property of non-object
。我使用简单的html dom来提取数据
答案 0 :(得分:0)
因为$ title14是字符串而不是对象,
你可以var_dump($title14);
知道它的类型。
ini_set("user_agent","Opera/9.80 (Windows NT 6.1; U; Edition Campaign 21; en-GB) Presto/2.7.62 Version/11.00");
$html14=file_get_html("https://www.gamesrocket.com/battlefield-1.html");
$title14 = $html14->find('span.price',0)->children(0)->plaintext;
for ($i=0; $i <sizeof($title14) ; $i++) {
if($title14[$i]){
echo $title14[$i];
$a13=$title14[$i];
}
else{
echo "problem";
}
}