添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

PHP是简单易用的web编程语言,研发人员可以很快的建立web项目,通过开源库可以成倍的提高效率,研发人员经常面临需要临时采集其它网站数据的需求,这种情况下相对来python等语言库就有所欠缺。GuzzleHttp通过代理IP的配合,就可以解决这一困惑,甚至通过异步请求和并发请求实现js扩展功能,结合symphony的Dom分析HTML页面Dom元素和XML文件就能快速采集数据啦。下面将部分代码列出:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Test16Proxy extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:16proxy';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$client = new \GuzzleHttp\Client();
// 要访问的目标页面
$targetUrl = "http://httpbin.org/ip";
// 代理服务器(产品官网 www.16yun.cn)
define("PROXY_SERVER", "t.16yun.cn:31111");
// 代理身份信息
define("PROXY_USER", "username");
define("PROXY_PASS", "password");
$proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);
$options = [
"proxy"  => PROXY_SERVER,
"headers" => [
"Proxy-Authorization" => "Basic " . $proxyAuth
]
];
//print_r($options);
$result = $client->request('GET', $targetUrl, $options);
var_dump($result->getBody()->getContents());
}
}
?>

PHP是简单易用的web编程语言,研发人员可以很快的建立web项目,通过开源库可以成倍的提高效率,研发人员经常面临需要临时采集其它网站数据的需求,这种情况下相对来python等语言库就有所欠缺。GuzzleHttp通过代理IP的配合,就可以解决这一困惑,甚至通过异步请求和并发请求实现js扩展功能,结合symphony的Dom分析HTML页面Dom元素和XML文件就能快速采集数据啦。下面将部分代码列出:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class Test16Proxy extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'test:16proxy';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$client = new \GuzzleHttp\Client();
// 要访问的目标页面
$targetUrl = "http://httpbin.org/ip";
// 代理服务器(产品官网 www.16yun.cn)
define("PROXY_SERVER", "t.16yun.cn:31111");
// 代理身份信息
define("PROXY_USER", "username");
define("PROXY_PASS", "password");
$proxyAuth = base64_encode(PROXY_USER . ":" . PROXY_PASS);
$options = [
"proxy"  => PROXY_SERVER,
"headers" => [
"Proxy-Authorization" => "Basic " . $proxyAuth
]
];
//print_r($options);
$result = $client->request('GET', $targetUrl, $options);
var_dump($result->getBody()->getContents());
}
}
?>


20-09-14 16:52