只能爬一个页面

<?php
function get_urls($url){ $url_array=array(); $the_first_content=file_get_contents($url); $the_second_content=file_get_contents($url); $pattern1 = "/http:\/\/[a-zA-Z0-9\.\?\/\-\=\&\:\+\-\_\'\"]+/"; $pattern2="/http:\/\/[a-zA-Z0-9\.]+/"; preg_match_all($pattern2, $the_second_content, $matches2); preg_match_all($pattern1, $the_first_content, $matches1); $new_array1=array_unique($matches1[0]); $new_array2=array_unique($matches2[0]); $final_array=array_merge($new_array1,$new_array2); $final_array=array_unique($final_array); for($i=0;$i<count($final_array);$i++) { echo $final_array[$i]."<br/>"; } } get_urls("http://www.yinghy.com"); ?>
<?php 

$string = GetHtmlCode("http://www.yinghy.com");
echo $string; function GetHtmlCode($url){
$ch = curl_init();//初始化一个cur对象
curl_setopt ($ch, CURLOPT_URL, $url);//设置需要抓取的网页
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//设置crul参数,要求结果保存到字符串中还是输出到屏幕上
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,1000);//设置链接延迟
$HtmlCode = curl_exec($ch);//运行curl,请求网页
return $HtmlCode;
}
function GetAllLink($string) {
$string = str_replace("\r","",$string);
$string = str_replace("\n","",$string);
$regex[url] = "((http|https|ftp|telnet|news):\/\/)?([a-z0-9_\-\/\.]+\.[][a-z0-9:;&#@=_~%\?\/\.\,\+\-]+)";
$regex[email] = "([a-z0-9_\-]+)@([a-z0-9_\-]+\.[a-z0-9\-\._\-]+)"; //去掉网页中的[]
$string = eregi_replace("\[|\]","",$string); //去掉JAVASCRIPT代码
$string = eregi_replace("<!--.*//-->","", $string); //去掉非<a>的HTML标签
$string = eregi_replace("</?[^aA][^<>]*>","",$string);
//分割$string中的所有链接
$output = split('</a>', $string);
for($i=0; $i<count($output); $i++){
$output_1 = split("<a", $output[$i]);
}
return $output_1;
}
function GetUserCareNews ($test,$keywords,$url) {
$messTxt = "";
$k=0;
$key = explode(";",$keywords); //自动为网站加载上http,避免网易邮箱链接错误,有一定的局限性
if(!ereg("http",$url)){
$url = "http://".$url;
} for($i=0; $i<count($test); $i++){
$test[$i] = eval('return'.iconv('gbk','utf-8',var_export($test[$i],true)).';');//修改编码
if(ereg("href", $test[$i]) && !ereg("href='#'",$test[$i])){//去掉无效链接
for($j=0; $j<count($key); $j++){ //支持多关键字
if(strpos($test[$i],$key[$j])!==false){
$mess[$k++]=ereg_replace($key[$j],"<font color=red>".$key[$j]."</font>", $test[$i]);//高亮关键字
}
}
}
}
$mess = array_unique($mess); //数组去重 //处理好发送链接,为链接加上网站根目录
for($l=0; $l<count($mess); $l++){
if(!ereg("http",$mess[$l]) && (strlen($mess[$l]) != 0)){//去掉空数组,这步很重要,如果不去掉直接影响后面链接的质量
$mess[$l] = eregi_replace("href=[\"']","",$mess[$l]);
$mess[$l] = $url.$mess[$l];
$mess[$l] = eregi_replace(" /","/",$mess[$l]);
if(ereg("'",$mess[$l])){
$mess[$l]="<a href='".$mess[$l]."</a>";
}
if(ereg("\"",$mess[$l])){
$mess[$l] = "<a href=\"".$mess[$l]."</a>";
}
}
else{
$mess[$l] = "<a ".$mess[$l]."</a>";
}
$messTxt .= $mess[$l];
$messTxt .= "<BR>";
}
return $messTxt;
} function SendEmail($to, $content) {
//Author:luofei
//$to 表示收件人地址,$content表示邮件正文内容 error_reporting(E_STRICT); //错误报告
date_default_timezone_set("Asia/Shanghai"); //设定时区 require_once("class.phpmailer.php");
require_once("class.smtp.php"); $mail = new PHPMailer(); //新建一个对象
$mail->CharSet = "UTF-8"; //设置编码,中文不会出现乱码的情况
$mail->IsSMTP(); //设定使用SMTP服务
$mail->SMTPDebug = 1; //启用SMTP调试功能i
//1 = errors and messages
//2 = messages only $mail->SMTPSecure = "tls"; //安全协议
$mail->Host = "smtp.googlemail.com"; //SMTP服务器
$mail->SMTPAuth = true; //启用SMTP验证功能
$mail->Username = "username@gmail.com"; //SMTP服务器用户名
$mail->Password = "******"; //SMTP服务器用户密码 $mail->From = "username@gmail.com"; //发件人
$mail->FromName = "Spider Service"; //发件人姓名(邮件上显示) $mail->AddAddress($to); //收件人地址
$mail->WordWrap = 50; //设置邮件正文每行的字符数
$mail->IsHTML(true); //设置邮件正文内容是否为html类型 $mail->Subject = "来自spider.html的邮件"; //邮件主题
$mail->Body = "<p>您好!<BR> <p>这是您感兴趣的内容</p> <BR>".$content." ";
//邮件正文
if(!$mail->Send()) //邮件发送报告
{
echo "发送邮件错误!";
}
else
{
echo "邮件发送成功!";
}
} ?>

  

PHP 网页爬虫的更多相关文章

  1. cURL 学习笔记与总结(2)网页爬虫、天气预报

    例1.一个简单的 curl 获取百度 html 的爬虫程序(crawler): spider.php <?php /* 获取百度html的简单网页爬虫 */ $curl = curl_init( ...

  2. c#网页爬虫初探

    一个简单的网页爬虫例子! html代码: <head runat="server"> <title>c#爬网</title> </head ...

  3. 网页爬虫--scrapy入门

    本篇从实际出发,展示如何用网页爬虫.并介绍一个流行的爬虫框架~ 1. 网页爬虫的过程 所谓网页爬虫,就是模拟浏览器的行为访问网站,从而获得网页信息的程序.正因为是程序,所以获得网页的速度可以轻易超过单 ...

  4. 网页爬虫的设计与实现(Java版)

    网页爬虫的设计与实现(Java版)     最近为了练手而且对网页爬虫也挺感兴趣,决定自己写一个网页爬虫程序. 首先看看爬虫都应该有哪些功能. 内容来自(http://www.ibm.com/deve ...

  5. Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)

    原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...

  6. [resource-]Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱

    reference: http://www.52nlp.cn/python-%e7%bd%91%e9%a1%b5%e7%88%ac%e8%99%ab-%e6%96%87%e6%9c%ac%e5%a4% ...

  7. 网页抓取:PHP实现网页爬虫方式小结

    来源:http://www.ido321.com/1158.html 抓取某一个网页中的内容,需要对DOM树进行解析,找到指定节点后,再抓取我们需要的内容,过程有点繁琐.LZ总结了几种常用的.易于实现 ...

  8. Java正则表达式--网页爬虫

    网页爬虫:其实就一个程序用于在互联网中获取符合指定规则的数据 爬取邮箱地址,爬取的源不同,本地爬取或者是网络爬取 (1)爬取本地数据: public static List<String> ...

  9. 从robots.txt開始网页爬虫之旅

    做个网页爬虫或搜索引擎(下面统称蜘蛛程序)的各位一定不会陌生,在爬虫或搜索引擎訪问站点的时候查看的第一个文件就是robots.txt了.robots.txt文件告诉蜘蛛程序在server上什么文件是能 ...

  10. Python网页爬虫(一)

    很多时候我们想要获得网站的数据,但是网站并没有提供相应的API调用,这时候应该怎么办呢?还有的时候我们需要模拟人的一些行为,例如点击网页上的按钮等,又有什么好的解决方法吗?这些正是python和网页爬 ...

随机推荐

  1. nginx下搭建fastcgi的开发环境

    在上一章最简单理解CGI,FastCGI,WSGI  我们将fastcgi规范类比HTTP.下面我们通过一个案例更加明白fastcgi 我们使用的是 nginx作为前端 代理,我们包装了gevent_ ...

  2. Popular Deep Learning Tools – a review

    Popular Deep Learning Tools – a review Deep Learning is the hottest trend now in AI and Machine Lear ...

  3. 具有 Button 风格的 Panel(覆盖TCustomPanel的Paint函数,用到了ThemeServices)

    unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  4. Hash unique和Sort unique

    SQL> set linesize 200 SQL> set pagesize 200 SQL> set autot trace SQL> select distinct de ...

  5. Unity 通过Animation实现控件位置的转换

    Unity版本:4.5.1 NGUI版本:3.6.5 参考链接:http://blog.csdn.net/unity3d_xyz/article/details/23035521,作者:CSDN in ...

  6. POJ-3468-A Simple Problem with Integers(区间更新,求和)-splay或线段树

    区间更新求和 主要用来练习splay树区间更新问题 //splay树的题解 // File Name: 3468-splay.cpp // Author: Zlbing // Created Time ...

  7. (转载)dl,dt,dd标记在网页中要充分利用

    (转载)http://www.jzxue.com/html/css/264I6DG6.html 我们在制作网页过程中用到列表时一般会使用<ul>或者<ol>标签,很少用刑< ...

  8. 搜索(三分):HDU 3400 Line belt

    Line belt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. 一招解决IE7无法访问https网页

    很多人都遇到过这种情况: 自己的IE访问不了https的网页了,如果你百度的话,有人会告诉你注册一堆的dll文件,或者更改IE设置啦什么的.上午,我也遇到这个问题,这些方法都不管用.请教了高手,将方法 ...

  10. Delphi stdCall意义

    Delphi stdCall意义 1.此代码所在单元是个库,可被别的应用来调用,像SysUtils.DateUtils.Classes等单元一样,都是为将来的无穷无尽的应用提供服务的.2.此代码还可能 ...