php小偷程序实例代码
小偷程序其实就是利用了php中的一特定函数实现采集别人网站的内容,然后通过正则分析把我们想要的内容保存到自己本地数据库了,下面我来介绍php小偷程序的实现方法,有需要的朋友可参考。
在下面采集数据过程中file_get_contents函数是关键了,下面我们来看看file_get_contents函数语法
string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败, file_get_contents() 将返回 FALSE。
file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。
例
代码如下 | 复制代码 |
$homepage = file_get_contents('http://www.hzhuti.com/'); |
这样$homepage就是我们采集网的内容给保存下来了,好了说了这么多我们开始吧。
例
代码如下 | 复制代码 |
function fetch_urlpage_contents($url){ //采集网页 $url="http://www.bkjia.com"; //要采集的地址 $ft["title"]["end"]=" $th["title"]["中山"]="广东"; //截取部分的替换 $ft["body"]["begin"]=" "; //截取的开始点$ft["body"]["end"]=""; //截取的结束点 $th["body"]["中山"]="广东"; //截取部分的替换 $rs=pick($url,$ft,$th); //开始采集 echo $rs["title"]; |
以下代码从上一面修改而来,专门用于提取网页所有超链接,邮箱或其他特定内容
小提示file_get_contents很是容易被防采集了,我们可以使用curl来模仿用户对网站进行访问,这算比上面要高级不少哦,file_get_contents()效率稍低些,常用失败的情况、curl()效率挺高的,支持多线程,不过需要开启下curl扩展。下面是curl扩展开启的步骤:
1、将PHP文件夹下的三个文件php_curl.dll,libeay32.dll,ssleay32.dll复制到system32下;
2、将php.ini(c:WINDOWS目录下)中的;extension=php_curl.dll中的分号去掉;
3、重启apache或者IIS。
简单的抓取页面函数,附带伪造 Referer 和 User_Agent 功能
代码如下 | 复制代码 |
function GetSources($Url,$User_Agent='',$Referer_Url='') //抓取某个指定的页面 |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
