一个数据采集类
复制代码 代码如下:
// 兼容 php4 php5
// 程序作者 张建 52linux.com(我爱Linux)
// 联系方法 733905@qq.com QQ 733905
// 简单调用方法
/*
include ("ugs.php"); // 你可以下载本ugs.phps 然后重命名为ugs.php
$ugs = new ugs();
$url = "http://domainname.com/path_to_your_target?param";
$ugs->seturl($url);
$ugs->gather();
//............这里可以调用本类里的其它方法,对$ugs->value_ 做调整,
以满足您的要求
$content=$ugs->getcontent();
print($content);
?>
*/
class ugs
{
var $value_ ; //'目标内容
var $src_ ; //'目标URL地址
function seturl($url)
{
$this->src_=$url;
}
function getcontent()
{
return $this->value_;
}
function getfile($url)
// 获取目标
{
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_parsed["port"];
if ($port==0) $port = 80;
$path = $url_parsed["path"];
if (empty($path))
$path="/";
if ($url_parsed["query"] != "")
$path .= "?".$url_parsed["query"];
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
$fp = fsockopen($host, $port, $errno, $errstr, 30);
fwrite($fp, $out);
$body = false;
while (!feof($fp))
{
$s = fgets($fp, 1024);
if ( $body ) $in .= $s;
if ( $s == "\r\n" )
$body = true;
}
fclose($fp);
return $in;
}
function getfile_curl($url)
{
$curl="/usr/local/bin/curl " ; // path to your curl
$curl_options=" -s --connect-timeout 10 --max-time 10 ";
// curl 用法请参考 curl --help 或者 man curl
// curl 参数非常之丰富,可以模拟各种浏览器(agent) 可以设置referer
$cmd="$curl $curl_options $url ";
@exec($cmd,$o,$r);
if($r!=0)
{
return "超时";
}
else
{
$o=join("",$o);
return $o;
}
}
function gather_curl($curl)
{
$http=$this->getfile_curl($this->src_);
return $this->value_=$http;
}
function gather_array($url)
{
return file($url);
}
function gather()
// 开始收集
{
$http=$this->getfile($this->src_);
return $this->value_=$http;
}
function gather_local($toline=true)
// 处理本地文件
{
if($toline)
{
$http=file($this->src_);
return $this->value_=$this->BytesToBstr($http);
}
else
{
$http=file($this->src_);
return $this->value_=$http;
}
}
function noReturn()
// 删除回车换行
{
$this->value_=str_replace("\n","",$this->value_);
$this->value_=str_replace("\r","",$this->value_);
}
function change($oldStr,$str)
//'对收集到的内容中的个别字符串用新值更换/方法
//'参数分别是旧字符串,新字符串
{
$this->value_=str_replace($oldStr,$str,$this->value_ );
}
function cut($start,$end,$no='1',$comprise='')
//'按指定首尾字符串对收集的内容进行裁减(不包括首尾字符串)方法
// $no 必须是 1,2 3 ... 不允许是0
//$comprise 可以选择 start 或者 end 或者 all 或者 什么都不填
{
$string=explode($start,$this->value_);
//print_r($string);
$string=explode($end,$string[$no]);
//print_r($string);
switch ($comprise){
case 'start':
$string=$start.$string[0];
break;
case 'end':
$string=$string[0].$end;
break;
case 'all':
$string=$start.$string[0].$end;
break;
default:
$string=$string[0];
}
return $this->value_=$string;
}
function filt($head,$bot,$str,$no='1',$comprise='')
//'按指定首尾字符串对收集的内容用新值进行替换(不包括首尾字符串)方法
// '参数分别是首字符串,尾字符串,新值,新值位空则为过滤
{
$tmp_v=$this->value_;
$tmp=$this->cut($head,$bot,$no,$comprise);
return $this->value_=str_replace($tmp,$str,$tmp_v);
}
function local()
{
//'将收集的内容中的绝对URL地址改为本地相对地址
// 还没实现
}
function replaceByReg($patrn,$str)
//'对收集的内容中的符合正则表达式的字符串用新值进行替换/方法
//'参数是你自定义的正则表达式,新值
{
return $this->value_=join("",preg_replace($patrn,$str,$this->value_));
}
function debug()
//调试显示
{
$tempstr="<script>function runEx(){var winEx2 = window.open(\"\", \"winEx2\", \"width=500,height=300,status=yes,menubar=no,scrollbars=yes,resizable=yes\"); winEx2.document.open(\"text/html\", \"replace\"); winEx2.document.write(unescape(event.srcElement.parentElement.children[0].value)); winEx2.document.close(); }function saveFile(){var win=window.open('','','top=10000,left=10000');win.document.write(document.all.asdf.innerText);win.document.execCommand('SaveAs','','javascript.htm');win.close();}</script>
echo $tempstr;
}
}
?>

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Linux 터미널에서 Python 버전을 보려고 할 때 Linux 터미널에서 Python 버전을 볼 때 권한 문제에 대한 솔루션 ... Python을 입력하십시오 ...

Docker 환경을 사용할 때 Docker 환경에 Extensions를 설치하기 위해 PECL을 사용하여 오류의 원인 및 솔루션. 종종 일부 두통이 발생합니다 ...

많은 웹 사이트 개발자는 램프 아키텍처에서 Node.js 또는 Python 서비스를 통합하는 문제에 직면 해 있습니다. 기존 램프 (Linux Apache MySQL PHP) 아키텍처 웹 사이트 요구 사항 ...

Linux 터미널에서 Python 사용 ...

Apscheduler 타이밍 작업을 MacOS 플랫폼의 서비스로 구성하십시오. Ngin과 유사한 APSCHEDULER 타이밍 작업을 서비스로 구성하려면 ...

언어의 멀티 스레딩은 프로그램 효율성을 크게 향상시킬 수 있습니다. C 언어에서 멀티 스레딩을 구현하는 4 가지 주요 방법이 있습니다. 독립 프로세스 생성 : 여러 독립적으로 실행되는 프로세스 생성, 각 프로세스에는 자체 메모리 공간이 있습니다. 의사-다일리트 레딩 : 동일한 메모리 공간을 공유하고 교대로 실행하는 프로세스에서 여러 실행 스트림을 만듭니다. 멀티 스레드 라이브러리 : PTHREADS와 같은 멀티 스레드 라이브러리를 사용하여 스레드를 만들고 관리하여 풍부한 스레드 작동 기능을 제공합니다. COROUTINE : 작업을 작은 하위 작업으로 나누고 차례로 실행하는 가벼운 다중 스레드 구현.

Linux 시스템과 함께 제공되는 Python 통역사를 제거하는 문제와 관련하여 많은 Linux 배포판이 설치 될 때 Python 통역사를 사전 설치하고 패키지 관리자를 사용하지 않습니다 ...

Web.xml 파일을 열려면 다음 방법을 사용할 수 있습니다. 텍스트 편집기 (예 : 메모장 또는 문자 메시지)를 사용하여 통합 개발 환경 (예 : Eclipse 또는 NetBeans)을 사용하여 명령을 편집하십시오 (Windows : Notepad Web.xml; Mac/Linux : Open -A Texted web.xml).
