Php 爬网以从其他网站获取特定内容
我有一个搜索框。。。。我想在框中输入某个值……我有一些网站的URL,这些网站上有所需的数据。例如Php 爬网以从其他网站获取特定内容,php,web-crawler,Php,Web Crawler,我有一个搜索框。。。。我想在框中输入某个值……我有一些网站的URL,这些网站上有所需的数据。例如 http://www.zafa.com.pk/tablets.html , http://www.zafa.com.pk/injections.html 当我点击搜索按钮时,脚本应该只返回那些内容与输入搜索值匹配的网站URL。请让我知道我该怎么做 我尝试了以下代码,但它对我不起作用 注意:我不是在搜索整个网站,我只是在搜索网站的某些页面 <?php $ch = curl_init();
http://www.zafa.com.pk/tablets.html , http://www.zafa.com.pk/injections.html
当我点击搜索按钮时,脚本应该只返回那些内容与输入搜索值匹配的网站URL。请让我知道我该怎么做
我尝试了以下代码,但它对我不起作用
注意:我不是在搜索整个网站,我只是在搜索网站的某些页面
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$data = curl_exec($ch);
file_put_contents("text.txt", $data);
curl_close($ch);
?>
您可以按如下方式执行: 注意:以下代码适用于单个网站。对于多个网站,您可以使用
explode()
和foreach
$searc_in = file_get_contents('http://www.zafa.com.pk/tablets.html');
$findme = 'CARDACE';
$pos = strpos($searc_in, $findme);
if ($pos === false) {
echo "The string '$findme' was not found in the website";
} else {
echo "The string '$findme' was found in the website";
echo " and exists at position $pos";
}