$ch = curl_init ("http://www.php.net/");
$fp = fopen ("php_homepage.txt", "w");
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
?>
int curl_init ([string url])
$ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, "http://www.zend.com/"); curl_setopt ($ch, CURLOPT_HEADER, 0); curl_exec ($ch); curl_close ($ch); ?>
bool curl_setopt (int ch, string option, mixed value)
<?php
class MultiHttpRequest{
public $urls = array();
public $curlopt_header = 0;
public $cookie_file = '';
public $collect_save_file = '';
public $start_timestamp = '';
public $end_timestamp = '';
private $log_handle = '';
private $collect_save_handle = '';
private $db_conn = false;
private $pre_break_goods_id = ''; //上一次强制退出的id
private $per_break_brand_id = ''; //上一次更新到的brand_id
private $main_log_id = ''; //本次更新的主表日志id
private $start_time = '';
public $login_session = '';
public $date_char = '';
private $mode = '';
private $sql_log_handle = '';
function __construct($upgrade_date='', $force_upt=false)
{
$this->mysql_init();
}
private function mysql_init(){
$db_name = 'dbname';
$db_user = 'name';
$db_pass = 'pass';
$db_host = 'localhost';
$db_conn = mysql_connect($db_host, $db_user, $db_pass) ;
if(!$db_conn){
echo '数据库连接失败!';
exit;
}
$this->db_conn = $db_conn;
mysql_select_db($db_name);
}
public function init_login(){
//第一步模拟登陆
$target_url = 'http://www.test.com/login.jsp';
//post 提交的数据
$post_fields = array(
'username' => '卓雅秀淘宝',
'password' => 'joarshow.taobao.com',
't_url' => '',
'Submit2' => ' 登 录 '
);
//保存登陆的cookie
$cookie_file = dirname(__FILE__).'/cookie_'.time().'.txt';
$this->cookie_file = $cookie_file;
//存cookie
$ch = curl_init($target_url);
curl_setopt($ch, CURLOPT_HEADER, 1);
// curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
$login_contents = curl_exec($ch);
curl_close($ch);
}
/**
* 测试
*
* @param unknown_type $test_url
*/
public function get_one_file($test_url){
$ch = curl_init($test_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_COOKIE, $this->login_session);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.test.com/welcome.shtml');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)');
$contents = curl_exec($ch);
curl_close($ch);
return $contents;
}
public function point_url_brand($url){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_COOKIE, $this->login_session);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.test.com/product.shtml');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)');
$contents = curl_exec($ch);
// echo htmlspecialchars($contents);exit;
curl_close($ch);
return $contents;
}
}
/**
* 根据地址抓取淘宝页面html代码
* @param type $url 地址
* @return boolean
*/
public function getTaoBaoHtml($url) {
if (empty($url)) {
return false;
}
$ch = curl_init();
// 设置 url
curl_setopt($ch, CURLOPT_URL, $url);
// 设置浏览器的特定header
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"User-Agent: {Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0}",
"Accept: {text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8}",
"Accept-Language: {zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3}",
"Cookie:{cq=ccp%3D1; cna=a7suCzOmSTECAXgg9iCf4AtX; t=671b2069c7e8ac444da66d664a397a5f; tracknick=%5Cu4F0D%5Cu6653%5Cu8F8901;
_tb_token_=nDiU1vCuzFd0; cookie2=c54709ffbe04a5ccb80283c34d6b00fa;
pnm_cku822=128WsMPac%2FFS4KgNn%2BYfhzduo4U2NC0zh9cAS4%3D%
7CWUCLjKhqr873bOIFQcMecSw%3D%7CWMEKRlV%
2B3D9a6XWaidNWNQOSWXwaXugvQHzhxALh%7CX0
YLbX78NUR2b2DHoxnIqZENQqR35TBZbfQ5vooI0b6GHZA3U1kr%7CXkdILog
Cr878ZK9I%2B%2FE3QjAD3lFJJaAZRA%3D%3D%7CXUeMwMR2s%
2BTUQk8IPP5TNgWfUjQwonccMCxihTa0fRYgtjgfa4j6%7CXMY
K7F8liOvH3hMUpzXkiaU%2FJw%3D%3D}",
));
// 页面内容我们并不需要
curl_setopt($ch, CURLOPT_NOBODY, 0);
// 只需返回HTTP header
curl_setopt($ch, CURLOPT_HEADER, 0);
// 返回结果,而不是输出它
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
ob_start();
curl_exec($ch);
$html = ob_get_contents();
ob_end_clean();
curl_close($ch);
return $html;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有