这里专门开个帖子用来整理采集遇到的问题

网上之前找的封装php curl的类,小巧且实用,用了挺久

PHPer 2020-04-06 1783 0 0

网上之前找的封装php curl的类,小巧且实用,用了挺久,比直接用php自带的curl要好很多,已经处理了一些问题,包括模拟浏览器等等。原文出处已经忘记了。 20200406

class cURL {

var $headers;

var $user_agent;

var $compression;

var $cookie_file;

var $proxy;

/**

* 初始化

*

* @param string $cookies

* @param string $cookie

* @param string $compression

* @param string $proxy

*/

function cURL($cookies = TRUE, $cookie = 'cookies.txt', $compression = 'gzip', $proxy = '') {

$this->headers [] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';

$this->headers [] = 'Connection: Keep-Alive';

$this->headers [] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';

$this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';

$this->compression = $compression;

$this->proxy = $proxy;

$this->cookies = $cookies;

if ($this->cookies == TRUE)

$this->cookie ( $cookie );

}

/**

* 配置cookie

*

* @param unknown $cookie_file

*/

function cookie($cookie_file) {

if (file_exists ( $cookie_file )) {

$this->cookie_file = $cookie_file;

} else {

fopen ( $cookie_file, 'w' ) or $this->error ( 'The cookie file could not be opened. Make sure this directory has the correct permissions' );

$this->cookie_file = $cookie_file;

fclose ( $this->cookie_file );

}

}

/**

* get方式打开页面

*

* @param unknown $url

* @return mixed

*/

function get($url) {

$process = curl_init ( $url );

curl_setopt ( $process, CURLOPT_HTTPHEADER, $this->headers );

curl_setopt ( $process, CURLOPT_HEADER, 0 );

curl_setopt ( $process, CURLOPT_USERAGENT, $this->user_agent );

if ($this->cookies == TRUE)

curl_setopt ( $process, CURLOPT_COOKIEFILE, $this->cookie_file );

if ($this->cookies == TRUE)

curl_setopt ( $process, CURLOPT_COOKIEJAR, $this->cookie_file );...

立即注册

更新于:2020-04-06 13:47:44
    您需要登录后才可以评论。 立即注册
    相关内容

    curl超时的设置

    PHP向js传数组

    PHP判断语句的类型判断???

    phpmyadmin问题整理

    phpmyadmin解决Failed to set session cookie. Maybe you are using HTTP...

    phpmyadmin 登录报错 mysqli_real_connect(): (HY000/2002):

    PhpMyAdmin 配置文件现在需要一个短语密码的解决方法

    PHP与APP

    PHP是否可以应用于App开发

    推荐内容

    分享几个好用的bt搜索bt资源下载网址网站

    影视电影剧集动漫综艺bt资源在线播放网址网站推荐分享

    全网最新bt磁力搜索引擎bt资源bt网站网址分享

    人气美女女优百度指数排行榜(波多野结衣,苍井空,三上悠亚,深田咏美,桥本有菜,北条...

    最强人造人深田咏美,业界的社交女王

    人生起起落落的三上悠亚,成名前的清纯风,怎么搭配出来的?

    业内第一大长腿,桥本有菜的腿究竟有多长

    波多野结衣,岛国业界著作最多的超级劳模

    日本AV界NO.1,苍井空是多少宅男的疯狂?

    美女女优视频混剪 This Girl-Laza Morgan

    怎样使用V2Ray代理和SSTap玩如魔兽世界/绝地求生/LOL台服/战地3/黑色沙漠/彩...

    sstap游戏代理教程 从此玩如魔兽世界/绝地求生/LOL台服/战地3/黑色沙漠/彩虹六...

    影视电影剧集动漫综艺bt资源在线播放网址网站推荐分享