我已尝试过两种办法,但并非如此之多的假设,所以我的html也一样:
<td>
<a href="..?ID=343">
<img src=".." />
</a>
</td>
<td>
<a href="..?id-343"> < - diffirence between two links is that this one has id in lowercase
Some text..
</a>
<td>
Now i want to get this element and this content: Some text..
我设法获得两种信息,但出于某种原因,如果一只印刷链接——信息一带有双重链接:
Array ( [0] => http://www.....net/2004/dealer_oglas.asp?id=5895417 [1] => http://www.....net/2004/dealer_oglas.asp?ID=5895417 [2] => http://www.....net/2004/dealer_oglas.asp?id=5883006 [3] => http://www.....net/2004/dealer_oglas.asp?ID=5883006 [4]
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.....net/2004/dealer_Zaloga.asp?dealer=12321");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$dom = new DOMDocument;
@$dom->loadHTML($output);
// Get images
$images = $dom->getElementsByTagName( img );
$image_array = array();
for($i = 0; $i < $images->length; $i++) {
if($images->item($i)->getAttribute( width ) == "80") {
array_push($image_array, $dom->saveHTML($images->item($i)));
}
}
// Get links
$links = $dom->getElementsByTagName( a );
$links_array = array();
$title_array = array();
//Here i try to compare the two a that it finds i want to store only the one that does not have img element right after it but for some reason it stores both.
// All arrays are the same size img, links title
for($j = 0; $j < $links->length; $j++) {
if(isset($image_array[$j]) && $dom->saveHTML($links->item($j+1)) != $image_array[$j]) {
array_push($links_array, http://www.....net/2004/ . $links->item($j)->getAttribute( href ));
array_push($title_array, $links->item($j)->nodeValue);
}
}
我试图比较 no子 如果其“或“......”但又不产生任何影响,则其数值。 事先得到所有帮助。