您好,欢迎访问一九零五行业门户网

CURL抓取的网页中,通过相对路径引用了其他页面,如何解决cookie问题?

curl 相对路径 cookie
例如,用curl抓取页面a,页面a通过相对路径引用了页面b,页面b有set-cookie的头部,而页面a没有set-cooike。
我只能curl抓取页面a,但是抓不到cookie,因为cookie是在页面b设置的。求高手解决问题!万分感激!
回复讨论(解决方案) 分两次/多次抓取
其实对于ajax/验证码等等都是这样做的
header(content-type:text/html;charset=utf-8); function request_by_curl($remote_server, $post_string) { $ch = curl_init(); curl_setopt($ch, curlopt_url, $remote_server); curl_setopt($ch, curlopt_postfields, $post_string); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_nobody, false); curl_setopt($ch, curlopt_header,true); curl_setopt($ch, curlopt_httpheader, array()); $data = curl_exec($ch); curl_close($ch); return $data; } //获取验证码 file_get_contents(http://jysx.scnu.edu.cn/verifyimg.aspx); $cookie = $http_response_header[6]; $code = substr($cookie,23,4); echo $code.
; //post登录 $remote_server = http://jysx.scnu.edu.cn/login.aspx; $post_string = 'act=login&type=ajax&name=20102301025&pass=523523&verify='.$code; echo request_by_curl($remote_server,$post_string);
这是我模拟登录华南师范大学抢实习的php代码,好像不行啊
可以了!!!!!
为什么这个网站会把验证码写到头信息里??
其它类似信息

推荐信息