任何人都可以帮助测试此代码并告诉我错误是什么吗?
预期结果为01223658060102111111
。但它像这样重复
01223658060102111111012236580601021111110122365806010211111101223658060102111111
这是我的代码
<?php
ini_set('user_agent', 'My-Application/2.5'); //without this file_get_content would not work
$saveURL = fopen("url.txt", "w");
$html = file_get_contents("http://www.carlist.my/used-cars/2592832/2004-toyota-camry-2-0.html");
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$cont = $xpath->evaluate("//ul[contains(@class, 'list-contact')]/li");
foreach($cont as $con){
echo $con->nodeValue;
}
答案 0 :(得分:1)
将此行替换为
$cont = $xpath->evaluate("//ul[contains(@class, 'list-contact')]/li");
到
$cont = $xpath->evaluate("//ul[contains(@class, 'list-contact')][1]/li");
答案 1 :(得分:1)
@ july77:如何拆分它们以获得结果0122365806和060102111111
$arr = array();
foreach($cont as $con){
$arr[] = $con->nodeValue;
}
$first = $arr[0];
$second = $arr[1];