dougong8012 2015-03-21 11:58
浏览 47

当使用simple_html_dom从远程站点读取内容时,Php foreach循环意外结束

I have this code:

$target_url = "http://mysiteexmpl.com/";
$html = new simple_html_dom();
$html->load_file($target_url);

//here I find specific links and start looping each
foreach($html->find('a.link') as $link){
$newtarget_url = $link->href;

//here I open each url that I find as new
$newhtml = new simple_html_dom();
$newhtml->load_file($newtarget_url);

//getting price
foreach($newhtml->find('div.pprice') as $price){
$price=preg_replace("/[^0-9.]/", "",$price);echo '<br>';
}

//getting other info and so on
foreach($newhtml->find('div.prohead > h1') as $title){
$title= $title->innertext;echo '<br>';
}

//here I execute several queries and copying images from remote site to mine
}

The problem is that my target url-s are 21 if I echo $newtarget_url and dont execute queries, but when execute the full code and queries loop stops on the 7-th url and dont loop over all 21 url-s that it is supposed to loop Is this a memory leak problem or something else? How to debug it? How can the code above be optimized?

Thank you in avance for your time

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭