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

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

WBOY
Release: 2016-06-23 14:13:12
Original
1411 people have browsed it

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."<br>";		//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);
Copy after login


这是我模拟登录华南师范大学抢实习的php代码,好像不行啊

可以了!!!!!

为什么这个网站会把验证码写到头信息里??

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template