喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
 11  1/2  1  2  > 
     
标题: [问题] 用curl怎么采不到“商务部”首页的内容啊?  
 
tom4599
新手上路
Rank: 1



UID 130198
精华 0
积分 8
帖子 6
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2008-6-26
状态 离线
用curl怎么采不到“商务部”首页的内容啊?

$url= "http://www.mofcom.gov.cn/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_COOKIEJAR,"d:\cookie.txt");
curl_setopt($ch,CURLOPT_COOKIEFILE,"d:\cookie.txt");
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_TIMEOUT,10);
$line = curl_exec($ch);
curl_close($ch);
2008-7-3 08:49 PM#1
查看资料  发短消息  顶部
 
tom4599
新手上路
Rank: 1



UID 130198
精华 0
积分 8
帖子 6
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2008-6-26
状态 离线
[推荐阅读] 请教数据库内容替代的一个问题
这是返回源代码

<html>
<head>
<meta http-equiv="refresh" content="0;URL=http://www.mofcom.gov.cn/?10489757=34509859"/>
</head>
</html>
2008-7-3 09:33 PM#2
查看资料  发短消息  顶部
 
LuckLrj (中国php中的爱因斯坦)
版主
Rank: 7Rank: 7Rank: 7
老会员


UID 64836
精华 0
积分 2600
帖子 3139
金钱 2600 喜悦币
威望 0
人脉 0
阅读权限 100
注册 2005-6-19
状态 离线
[推荐阅读] 关于 “两点之间最短的距离”外谈!
转向了,也许你有什么没构造全的。



学习,工作累了,请访问我的小站,娱乐一下。http://www.52sunny.net
2008-7-3 10:57 PM#3
查看资料  Blog  发短消息  顶部
 
tom4599
新手上路
Rank: 1



UID 130198
精华 0
积分 8
帖子 6
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2008-6-26
状态 离线
[推荐阅读] 没有工作啊~~~~
curl怎么采转向的地址啊?

curl怎么采转向的地址啊?
2008-7-3 11:28 PM#4
查看资料  发短消息  顶部
 
yanglei1979 (高老庄二庄主)
高级会员
Rank: 4
天蓬元帅


UID 73676
精华 0
积分 763
帖子 752
金钱 763 喜悦币
威望 0
人脉 0
阅读权限 50
注册 2006-5-19
来自 深圳
状态 离线
[推荐阅读] 网龙公司诚聘IT优秀人才!(7.1更新!)
换个函数呢,比如用 file()



今霄酒醒何处?杨柳岸,晓风残月。
2008-7-3 11:56 PM#5
查看资料  访问主页  发短消息  QQ . .   Yahoo!  顶部
 
guog
论坛元老
Rank: 8Rank: 8



UID 79936
精华 0
积分 9716
帖子 439
金钱 9716 喜悦币
威望 0
人脉 0
阅读权限 90
注册 2006-9-12
来自 北京
状态 离线
[推荐阅读] A股:为了忘却的纪念


<?php
class cURL 
  
/*
  * @author Keith Kurson ([email]delusions@gmail.com[/email])
  * @date September 09, 2006
  * @version 1.0
  */
     /*
     * Headers
     */
     
var $headers;
     
/*
     * User Agent
     */
     
var $user_agent;
     
/* 
     * Compression 
     */
     
var $compression;
     
/*
     * Cookie File
     */
     
var $cookie_file;
     
/* 
     * Proxy Server
     * ip:port
     */
     
var $proxy;
     
/* 
     * Initiate the class
     */
     
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";
           
$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); 
     }
     
/* 
     * Tests the 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($cookie_file);
          }
     }
     
/*
     * Runs a GET through cURL
     */
     
function get($url,$refer='') {
          
$process curl_init($url);
          
curl_setopt($processCURLOPT_REFERER$refer);
          
curl_setopt($processCURLOPT_HTTPHEADER$this->headers);
          
curl_setopt($processCURLOPT_USERAGENT$this->user_agent);
          if (
$this->cookies == TRUEcurl_setopt($processCURLOPT_COOKIEFILE$this->cookie_file);
          if (
$this->cookies == TRUEcurl_setopt($processCURLOPT_COOKIEJAR$this->cookie_file);
          
curl_setopt($process,CURLOPT_ENCODING $this->compression);
          
curl_setopt($processCURLOPT_TIMEOUT30);
          if (
$this->proxycurl_setopt($cUrlCURLOPT_PROXY'proxy_ip:proxy_port');
          
curl_setopt($processCURLOPT_RETURNTRANSFER1);
          
$return curl_exec($process);
          
curl_close($process);
          return 
$return;
     }
     
/* 
     * Runs a POST through cURL
     */
     
function post($url,$data,$refer) {
          
$process curl_init($url);
          
curl_setopt($processCURLOPT_REFERER$refer);
          
curl_setopt($processCURLOPT_HTTPHEADER$this->headers);
          
curl_setopt($processCURLOPT_USERAGENT$this->user_agent);
          if (
$this->cookies == TRUEcurl_setopt($processCURLOPT_COOKIEFILE$this->cookie_file);
          if (
$this->cookies == TRUEcurl_setopt($processCURLOPT_COOKIEJAR$this->cookie_file);
          
curl_setopt($processCURLOPT_ENCODING $this->compression);
          
curl_setopt($processCURLOPT_TIMEOUT30);
          if (
$this->proxycurl_setopt($cUrlCURLOPT_PROXY'proxy_ip:proxy_port');
          
curl_setopt($processCURLOPT_POSTFIELDS$data);
          
curl_setopt($processCURLOPT_RETURNTRANSFER1);
          
curl_setopt($processCURLOPT_FOLLOWLOCATION1);
          
curl_setopt($processCURLOPT_POST1);
          
$return curl_exec($process);
          
curl_close($process);
          return 
$return;
     }
     
/*
     * Error Output
     */
     
function error($error) {
          echo 
"<center><div style='width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px'><b>cURL Error</b><br>$error</div></center>";
          die;
     }
}
?>




没有
2008-7-4 09:39 AM#6
查看资料  Blog  发短消息  顶部
 
bxhcsz
新手上路
Rank: 1



UID 92095
精华 0
积分 49
帖子 47
金钱 49 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-4-27
状态 离线
[推荐阅读] dirname(__FILE__)效率低吗?
试了下子,首页的内容可以采到啊,CURLOPT_COOKIEFILE?你不是单纯的要采集内容么?



<?php新人,幻想在坛子里学到各位大牛的精髓,某天李彦宏请我出山,可我就不去.......
2008-7-4 09:42 AM#7
查看资料  Blog  发短消息  顶部
 
tom4599
新手上路
Rank: 1



UID 130198
精华 0
积分 8
帖子 6
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2008-6-26
状态 离线
[推荐阅读] 哎, 我的一邻居炒 "中石油" 成了百万富翁!!
回复 #7 bxhcsz 的帖子

不行啊,我那个代码里,$line的值是
"<html>
<head>
<meta http-equiv="refresh" content="0;URL=http://www.mofcom.gov.cn/?10489757=34509859"/>
</head>
</html>"
你看到了首页是跳转过去的首页,$line的值不是源代码
2008-7-4 10:15 AM#8
查看资料  发短消息  顶部
 
tom4599
新手上路
Rank: 1



UID 130198
精华 0
积分 8
帖子 6
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2008-6-26
状态 离线
[推荐阅读] 请高手帮忙写个递归,谢谢!!!
回复 #3 LuckLrj 的帖子

怎么才叫构造全呢?
2008-7-4 10:16 AM#9
查看资料  发短消息  顶部
 
tom4599
新手上路
Rank: 1



UID 130198
精华 0
积分 8
帖子 6
金钱 8 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2008-6-26
状态 离线
[推荐阅读] http://sourceforge.net/被和谐了
回复 #5 yanglei1979 的帖子

file()也是同样的问题
2008-7-4 10:17 AM#10
查看资料  发短消息  顶部
 11  1/2  1  2  > 
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.031567 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP