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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
