php使用curl登录人人网抓取信息

当初做一个网站,需要实现“用户分享本站,当有人点击时,用户的头像和链接排到第一位”这样的功能。于是找php登录人人网的方法,结果找到的函数都是失效的,原因是人人网的登录过程是多层301跳转。于是就自己写了一个方法。
可惜的是,这个东西并没起到吸引流量的作用。根本没人用这个,所以我把这个功能去掉了。

$post_fields['email'] = 'xxx@126.com'; //人人网用户名
$post_fields['password'] = 'xxxxxxx';  //人人网密码
$post_fields["isplogin"]="true";
 
function getlocation($str){
	if(strpos($str,"Location: ")){
		$array=explode("Location: ",$str);
		$array=explode("\n",$array[1]);
		return $array[0];
	}else{
		return '';
	}
}
function open($url,$post_fields,$cookie=''){
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5');
	curl_setopt($ch, CURLOPT_HEADER, true); //启用时会将头文件的信息作为数据流输出。
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //讲curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); //启用时会将服务器服务器返回的“Location:”放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
	curl_setopt($ch, CURLOPT_AUTOREFERER, 1); //自动设置header中的referer信息
	curl_setopt($ch, CURLOPT_POST, 1); //启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); //在HTTP中的“POST”操作。如果要传送一个文件,需要一个@开头的文件名
	curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
	$cookie_file = tempnam('../click','cookie');//cookie文件存放在网站根目录的click文件夹下
	curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); //连接关闭以后,存放cookie信息的文件名称
	$contents=curl_exec($ch);
	curl_close($ch);
	$url = trim(urldecode(getlocation($contents)));
	if($url!=''){
		$contents = open($url,$post_fields,$cookie_file); //如果存在301跳转,就跳到新地址。
	}
	if($cookie!=''&&file_exists($cookie)){
		unlink($cookie);
	}
	if($cookie_file!=''&&file_exists($cookie_file)){
		unlink($cookie_file);
	}
	return $contents;
}
黄网站2021-04-23 9:36:45

Hello Dear, are you truly visiting this web page on a regular basis, if so afterward you will without doubt take good knowledge.

buy cialis online2021-04-24 5:30:16

What’s Going down i’m new to this, I stumbled upon this I have found It absolutely useful and it
has aided me out loads. I am hoping to give a
contribution & aid different users like its helped me.
Good job.

fake gucci belt2021-04-28 7:25:20

Terrific work! This is the type of information that are meant to
be shared across the web. Disgrace on the search engines for now
not positioning this publish upper! Come on over
and consult with my web site . Thanks =)

ทางเข้า fun88 ล่าสุด2021-04-28 20:15:00

This is a topic that is close to my heart…
Cheers! Exactly where are your contact details though?

카지노사이트쿠폰2021-04-28 21:20:32

Why people still use to read news papers when in this technological world all is available on net?

m.fun78.com2021-04-28 21:40:40

Hi there! This post could not be written much better!
Reading through this article reminds me of my previous roommate!
He continually kept preaching about this. I’ll send this
post to him. Pretty sure he’ll have a great read.
Many thanks for sharing!

seo agency2021-04-28 22:24:36

Attractive portion of content. I simply stumbled upon your website and in accession capital
to say that I acquire in fact loved account your
weblog posts. Any way I will be subscribing for your augment
or even I achievement you get entry to persistently fast.

horny babes2021-04-30 14:52:11

When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment
is added I get three emails with the same comment.
Is there any way you can remove people from that
service? Thanks a lot!

corporate logo pinnacle golf balls2021-05-02 17:49:11

Hi! Quick question that’s totally off topic. Do you know how to make your site mobile friendly?

My weblog looks weird when viewing from my apple iphone.
I’m trying to find a template or plugin that might be able to fix
this problem. If you have any suggestions, please share.
Thanks!

Pamela Klemme2021-05-02 22:15:56

If you would like to obtain a great deal from this piece of writing then you have to apply
these techniques to your won blog.

Rickey Kornblatt2021-05-02 22:38:23

Hi there, constantly i used to check blog posts here early in the daylight, since i enjoy to learn more and more.

swim shop2021-05-03 3:28:08

Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve truly enjoyed browsing
your blog posts. In any case I will be subscribing for your feed
and I’m hoping you write once more very soon!

Sac gucci faux2021-05-05 15:52:40

Ahaa, its nice conversation regarding this piece
of writing at this place at this webpage, I have read all that, so now me also commenting
here.

验证码