1
爆炸我想分析從外部網頁的一些數據(遊戲名): https://www.mol.com/Product/GamesHive使用時,某些數據丟失在PHP
使用此代碼:
<?php
$url = 'https://www.mol.com/Product/GamesHive';
$content = file_get_contents($url);
$first_step = explode('<div class="col-xs-4">', $content);
$second_step = explode('</div>', $first_step[1]);
echo $second_step[0];
?>
但是有些數據會丟失。原始頁面有384
項目,我的頁面只有169
項目。有什麼問題?
因爲某些元素可能包含額外'class'或'id' – Tushar
問題是當'
不要在html上使用像這樣的字符串操作。並非所有的「col-xs-4」標籤都是這樣的,例如''將由爆炸得到MISSED''div class =「col-xs-4 xs-margin-bottom-40」>。使用DOM解析器和xpath來獲取任何你想要的。 –