【发布时间】:2014-07-01 13:05:23
【问题描述】:
我没有真正使用 PHP 的经验,如果我没有正确解释自己,请原谅。
我们有一个非常简单的爬虫,我们发现它是免费资源,但我们想让它变得更好:
当它找到并打印这个 div 时,其中有一个类为 price-ext 的 span。我想根据跨度的内容使用if 语句过滤回声输出。如果price-ext 类的跨度等于“v.o.n.”,则不要打印 div。如果内容有什么不同,那么echo $post可以通过。
<?php
include_once('simple_html_dom.php');
$target_url="http://www.funda.nl/koop/heel-nederland/inbeeld/sorteer-datum-af/";
$html = new simple_html_dom();
$html->load_file($target_url);
foreach($html->find('div[class=specs]') as $post)
{
echo $post."<br />";
}
?>
【问题讨论】:
-
为什么不能在
echo内部foreach循环之前分析$post?可以使用正则表达式或strpos()之类的函数。有什么问题? -
到目前为止,我只尝试了 ProfGhost 也建议的东西,但它不起作用。我猜是因为它看的是 $post 而不是里面的 span。我目前正在查看您对使用
strpos()的建议,但是我不熟悉它,所以我目前正在尝试解决。
标签: php web-crawler