使用安全登录刮取网站内容的特定区域

时间:2012-06-25 06:36:00

标签: html curl scrape

我正在尝试抓取登录安全网站的某些特定文本 这是使用curl的教程 http://www.digeratimarketing.co.uk/2008/12/16/curl-page-scraping-script/

但我无法将此实现到我的卷曲代码中 这是我的卷曲脚本

$url = "http://aftabcurrency.com/login_script.php";

$ch = curl_init();    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

curl_setopt($ch, CURLOPT_URL, $url); 
$cookie = 'cookies.txt';
$timeout = 30;

curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_TIMEOUT,         10); 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,  $timeout );
curl_setopt($ch, CURLOPT_COOKIEJAR,       $cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE,      $cookie);

curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch,CURLOPT_POSTFIELDS,"user_name=user&user_password=pass&passcode=code");     

$result = curl_exec($ch); 
curl_close($ch); 
$source = $result;
if(preg_match("/(CC3300\">)(.*?)(<\/font>)/is",$source,$found)){
echo $found[2];
}else{
echo "Text not found.";
}

例如aftabcurrency.com我只想废弃“我们的服务很重要!” (这个文字每天都在变化)

1 个答案:

答案 0 :(得分:1)

我要做的是在开始和开始之间“剪切”一个文本......在源文本中,文本以文本颜色613A75开始,并且以关闭&lt; /字体&GT; tag ..这是一个正则表达式解决方案:

$source = file_get_contents("http://aftabcurrency.com/index.php");
if(preg_match("/(613A75\">)(.*?)(<\/font>)/is",$source,$found)){
echo $found[2];
}else{
echo "Text not found.";
}

如果您想在会员区内使用您的文字执行此操作,请在此处将我的来源添加到您的来源并使用$ source = $ result

替换$ source = file_get_contents ...

还有其他方法可以做到这一点,DomDocument和xpath或简单的strpos / strstr / substr php函数。