Php 使用curl和simplehtmldom创建条件语句
我正在构建一个简单的webscraper,它可以访问一些URL并获取一些信息,但如果页面包含特定的文本内容,我希望退出当前循环并继续下一个循环,唯一奇怪的是我可以输出用于创建条件的标签,但它不起作用,好像那根本不存在 我的代码:Php 使用curl和simplehtmldom创建条件语句,php,curl,web-scraping,simple-html-dom,Php,Curl,Web Scraping,Simple Html Dom,我正在构建一个简单的webscraper,它可以访问一些URL并获取一些信息,但如果页面包含特定的文本内容,我希望退出当前循环并继续下一个循环,唯一奇怪的是我可以输出用于创建条件的标签,但它不起作用,好像那根本不存在 我的代码: for($i = 0; $i< 5; $i++){ curl_setopt($ch, CURLOPT_URL, 'url/details.php?med_id='.$i); curl_setopt($ch, CURLOPT_POST, false); curl_s
for($i = 0; $i< 5; $i++){
curl_setopt($ch, CURLOPT_URL, 'url/details.php?med_id='.$i);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, "");
$answer = curl_exec($ch);
//echo $answer;
if (curl_error($ch)) {
echo curl_error($ch);
}
$html = str_get_html($answer);
$table = $html->find('table', 3);
/*
*$table->find('td',17)->plaintext => could be "Comercializado" or "Não comercializado", so if is "Não comercializado" it goes to the next iteration.
I already output the text "$table->find('td',17)->plaintext" to see if appeaars and looks ok.
*/
if (strpos($table->find('td',17)->plaintext, 'Não comercializado') !== false) {
continue;
}
echo "<tr>";
echo "<td>".$table->find('td',17)."</td>";
echo "<td>".$table->find('td',14)."</td>";
echo " <td>".$table->find('td',22)."</td>";
echo "<td>".$table->find('td',25)."</td>";
echo "</tr>";
}
echo "</table>";
($i=0;$i<5;$i++)的{
curl_setopt($ch,CURLOPT_URL,'URL/details.php?med_id='。$i);
curl_setopt($ch,CURLOPT_POST,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,”);
$answer=curl_exec($ch);
//回音$答案;
if(旋度误差($ch)){
回波旋度误差($ch);
}
$html=str_get_html($answer);
$table=$html->find('table',3);
/*
*$table->find('td',17)->明文=>可以是“Comercializado”或“Não Comercializado”,因此如果是“Não Comercializado”,则会进入下一次迭代。
我已经输出了文本“$table->find('td',17)->plaintext”,以查看是否出现并看起来正常。
*/
if(strpos($table->find('td',17)->纯文本,'Não comercializado')!==false){
继续;
}
回声“;
echo“$table->find('td',17)”;
echo“$table->find('td',14)”;
echo“$table->find('td',22)”;
echo“$table->find('td',25)”;
回声“;
}
回声“;
请提供源代码或url的示例,您可能需要检查Não
是否编码为ã代码>或ã
。请提供源代码或url的示例,您可能需要检查Não
是否编码为ã代码>或ã代码>。