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;
}
qqemas2021-04-03 6:04:39

What’s up, yup this paragraph is truly pleasant and I have learned
lot of things from it regarding blogging. thanks.

putlocker2021-04-03 7:41:38

An impressive share! I have just forwarded this onto a colleague who had been doing a little research on this.
And he actually bought me lunch due to the fact that I stumbled upon it for
him… lol. So let me reword this…. Thanks
for the meal!! But yeah, thanx for spending some time to talk about this topic here on your internet site.

worldfree4uws2021-04-03 10:52:58

Hello there, just became aware of your blog through Google, and found that it is really informative.
I’m gonna watch out for brussels. I will be grateful
if you continue this in future. A lot of people will be
benefited from your writing. Cheers!

카지노커뮤니티2021-04-03 10:54:26

Hmm it appears like your site ate my first comment (it was extremely long)
so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to
everything. Do you have any points for newbie blog writers?

I’d genuinely appreciate it.

กระโจมอบสมุนไพร2021-04-03 11:57:07

I don’t know if it’s just me or if everybody else encountering problems with your site.
It looks like some of the text on your content are running off the screen. Can somebody else please provide feedback and let me know
if this is happening to them too? This may be a problem with my browser
because I’ve had this happen before. Kudos

Cara Hack Instagram2021-04-03 13:19:11

Do you have a spam problem on this site; I also am a blogger,
and I was curious about your situation; many of us have
developed some nice procedures and we are looking to swap techniques with others, be sure to
shoot me an e-mail if interested.

카지노사이트순위2021-04-03 14:35:04

Hi there would you mind letting me know which webhost you’re working with?
I’ve loaded your blog in 3 different web browsers and I must say this blog loads a
lot quicker then most. Can you suggest a good internet hosting provider at a fair price?
Thanks a lot, I appreciate it!

หวย2021-04-03 14:45:33

Hey this is kind of of off topic but I was wondering if
blogs use WYSIWYG editors or if you have to manually
code with HTML. I’m starting a blog soon but have no coding skills so I wanted to get
advice from someone with experience. Any help would be greatly appreciated!

monday motivation quotes for work2021-04-04 0:38:01

Spot on with this write-up, I really think this amazing site
needs a lot more attention. I’ll probably be returning to see more, thanks for the
info!

primewire2021-04-04 4:56:23

I relish, result in I found exactly what I used to be taking a look for.
You’ve ended my four day lengthy hunt! God Bless you man. Have a nice day.
Bye

instagram followers apk hack2021-04-04 8:05:50

Its not my first time to pay a visit this web page, i am visiting this site dailly and take pleasant data from here everyday.

Wesley2021-04-04 9:18:38

Thankfulness to my father who told me on the topic of this
weblog, this web site is genuinely awesome.

prediksi bola jitu gratis2021-04-04 17:40:21

You could certainly see your enthusiasm in the work you
write. The sector hopes for more passionate writers
such as you who aren’t afraid to say how they believe.
At all times follow your heart.

travis scott reebok2021-04-04 18:09:18

Wow! This blog looks just like my old one! It’s
on a totally different topic but it has pretty much the same
layout and design. Outstanding choice of colors!

수원셔츠룸2021-04-04 20:45:27

Good day! I know this is kind of off topic but I was wondering if you knew where I could find a
captcha plugin for my comment form? I’m using the
same blog platform as yours and I’m having trouble finding one?

Thanks a lot!

работа в такси2021-04-05 8:42:24

Hello there I am so thrilled I found your weblog, I
really found you by error, while I was searching on Yahoo for something else, Anyways I am here now and would just like to
say many thanks for a fantastic post and a all round enjoyable blog (I also love the theme/design), I don’t have time to go through it
all at the minute but I have saved it and also added in your RSS feeds, so when I have time I will be
back to read a lot more, Please do keep up the excellent work.

iclub2021-04-05 14:41:31

Wow, this post is pleasant, my younger sister is analyzing these things, thus I am going to
tell her.

Waste recycling Gloucester2021-04-05 16:39:52

Hello, I check your new stuff on a regular basis.
Your humoristic style is awesome, keep it up!

https://tocal.instructure.com/eportfolios/11910/Home/Oracle_1Z0104720_Provide_PDF_For_Guaranteed_Employment2021-04-05 18:46:17

I read this post fully about the difference of
newest and previous technologies, it’s amazing article.

Torrent Project2021-04-05 20:42:57

Its like you learn my mind! You seem to know so much approximately
this, such as you wrote the guide in it or something.
I believe that you simply could do with a few p.c.
to power the message house a little bit, but other than that, that is magnificent blog.
A great read. I’ll certainly be back.

tech2021-04-05 23:26:20

This paragraph will assist the internet users for building up new weblog
or even a blog from start to end.

Hfive5555.com2021-04-06 0:57:26

Thank you for the good writeup. It in fact was a amusement
account it. Look advanced to far added agreeable
from you! By the way, how can we communicate?

sofaloka2021-04-06 3:16:00

First off I would like to say wonderful blog! I had a quick question which I’d like to
ask if you do not mind. I was interested to find out how you center yourself and clear your head prior to writing.
I have had a tough time clearing my mind in getting my ideas out there.
I truly do take pleasure in writing but it just seems like the first 10 to 15 minutes tend to be lost just trying to figure out how to begin. Any suggestions
or hints? Appreciate it!

worldfree4u-lol2021-04-06 4:37:37

Great blog here! Also your website loads up very fast!
What web host are you using? Can I get your affiliate link to your host?
I wish my site loaded up as fast as yours lol

putlocker2021-04-06 4:39:51

I’m gone to inform my little brother, that he should
also go to see this web site on regular basis to take updated from
latest news update.

baidu2021-04-06 12:08:11

My partner and I stumbled over here from a different web address and thought I
may as well check things out. I like what I see so i am just following you.
Look forward to finding out about your web page yet again.

Streaming Jav Online Free2021-04-06 14:23:51

Hi there i am kavin, its my first occasion to commenting anywhere, when i read this piece of writing i thought i could also make
comment due to this brilliant piece of writing.

福克2021-04-06 18:56:58

I loved as much as you will receive carried out
right here. The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get got an shakiness over that you wish be delivering
the following. unwell unquestionably come further formerly
again as exactly the same nearly a lot often inside case you shield this increase.

Atollo Lamp Copper2021-04-07 1:09:04

Hmm it seems like your site ate my first comment (it was
extremely long) so I guess I’ll just sum it up what I submitted and
say, I’m thoroughly enjoying your blog. I too am an aspiring blog blogger but I’m still new to everything.

Do you have any recommendations for rookie blog writers?
I’d certainly appreciate it.

验证码