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

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

$post_fields['email'] = '[email protected]'; //人人网用户名
$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;
}
Melvintharo2021-06-25 8:18:46

You actually mentioned this fantastically!
hhttps://cadmed-bb.com/# most reliable canadian pharmacies

Melvintharo2021-06-25 9:22:46

Nicely put. Kudos.
hhttps://cadmed-bb.com/# mexican online pharmacies

Melvintharo2021-06-27 2:03:51

Thanks a lot, Quite a lot of facts.
hhttps://cadmed-bb.com/# buy cialis

Melvintharo2021-06-27 3:21:41

Awesome info. Regards.
hhttps://cadmed-bb.com/# canada pharmacies prescription drugs

addons.mozilla.org2021-06-27 8:28:29

Hey! I know this is kinda off topic but I’d figured I’d
ask. Would you be interested in trading links or maybe guest writing
a blog article or vice-versa? My blog covers a lot of the same
subjects as yours and I feel we could greatly benefit from each other.
If you are interested feel free to send me an email.

I look forward to hearing from you! Wonderful blog by
the way!

Free Sex Thai Porn Tube2021-07-01 2:02:58

Hello, Neat post. There is a problem along with your web site
in internet explorer, could check this? IE still is the marketplace leader and a
large element of people will leave out your magnificent writing due to this problem.

cartier love bracelet replica uk2021-07-01 22:30:37

Hello, just wanted to tell you, I enjoyed this post. It was funny.
Keep on posting!

cardboard boxes2021-07-09 1:44:47

Having read this I thought it was rather enlightening. I appreciate you finding the time and
energy to put this article together. I once again find myself personally spending a
significant amount of time both reading and commenting. But so what, it
was still worth it!

fendi backpack fake2021-07-11 16:58:36

I have been surfing on-line greater than three hours as of late,
yet I never found any fascinating article like yours. It is lovely price enough
for me. In my opinion, if all webmasters and bloggers made good content as you did, the web will likely
be a lot more helpful than ever before.

Lolitonus04732021-07-12 22:54:29

XEvil – the best captcha solver tool with unlimited number of solutions, without thread number limits and highest precision!
XEvil 5.0 support more than 12.000 types of image-captcha, included ReCaptcha, Google captcha, Yandex captcha, Microsoft captcha, Steam captcha, SolveMedia, ReCaptcha-2 and (YES!!!) ReCaptcha-3 too.

1.) Flexibly: you can adjust logic for unstandard captchas
2.) Easy: just start XEvil, press 1 button – and it’s will automatically accept captchas from your application or script
3.) Fast: 0,01 seconds for simple captchas, about 20..40 seconds for ReCaptcha-2, and about 5…8 seconds for ReCaptcha-3

You can use XEvil with any SEO/SMM software, any parser of password-checker, any analytics application, or any custom script:
XEvil support most of well-known anti-captcha services API: 2Captcha, RuCaptcha, AntiGate.com (Anti-Captcha.com), DeathByCaptcha, etc.

Interested? Just search in Google “XEvil” for more info
You read this – then it works! ;)))

Regards, Lolitynus4237

XEvil.Net

bird o'gorman flute2021-07-14 2:32:44

This paragraph presents clear idea in support of the new users of blogging, that genuinely how to do running a blog.

ไม่มีเสาจะลอง adapt2021-07-14 4:50:45

This information is invaluable. How can I find out more?

cocaine nasal spray2021-07-16 4:35:47

hey there and thank you for your information – I’ve definitely picked up anything new from right here.
I did however expertise a few technical issues using this web site, since I experienced to reload the site lots of times
previous to I could get it to load properly. I had been wondering if your hosting is OK?
Not that I am complaining, but sluggish loading instances times will very
frequently affect your placement in google
and could damage your high quality score if advertising and marketing with Adwords.
Well I’m adding this RSS to my email and could look out for much more of your respective exciting
content. Make sure you update this again soon.

“Reverse cowgirl” ท่า sex ให้เธอคุมเกม2021-07-24 14:16:38

Link exchange is nothing else except it is only placing
the other person’s web site link on your page at appropriate place and other person will also do similar in support of
you.

mybet88 free credit2021-08-03 20:48:31

It’s hard to find educated people in this particular topic, however,
you sound like you know what you’re talking about! Thanks

annualeventpost.com2021-08-11 5:21:33

Hello, just wanted to tell you, I loved this post. It was inspiring.
Keep on posting!

cartier ring replica2021-09-09 0:42:26

Hello there, I think your blog could possibly be having browser compatibility issues.
Whenever I look at your web site in Safari, it looks fine
however, when opening in I.E., it’s got some overlapping issues.
I merely wanted to give you a quick heads up! Other than that, excellent website!

gucci replica belts2021-09-09 22:50:37

Hi would you mind sharing which blog platform you’re using?
I’m planning to start my own blog in the near future
but I’m having a difficult time choosing between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your design seems different then most blogs and I’m looking for something
unique. P.S My apologies for getting off-topic but
I had to ask!

อัปเลเวลต่อจากท่า mayalounge.net web sex2021-09-12 8:19:55

Way cool! Some extremely valid points! I appreciate you writing this write-up plus the
rest of the website is really good.

Amateur mayalounge web sex thai teen girlfriend wakes up her big dick boyfriend for mayalounge.net web sex2021-09-15 16:33:24

This is a very good tip particularly to those new to the blogosphere.
Brief but very precise information… Appreciate your sharing this one.
A must read article!

fake louis vuitton wallet2021-09-16 0:12:21

Heya i’m for the primary time here. I came across this board and I
to find It truly useful & it helped me out much.
I hope to offer one thing again and aid others like you aided me.

sex offender registry map az2021-09-17 12:59:18

I read this article fully concerning the resemblance of newest and preceding technologies,
it’s awesome article.

//Sc.Devb.gov.hk/TuniS/ketotrimplusadvanced.com2021-09-27 9:26:02

Perfect piece of work you have done, this internet site is really cool with excellent information.

wholesale bridgestone golf balls2021-10-03 23:20:44

I’m really impressed with your writing abilities and also with the structure in your weblog.

Is this a paid subject or did you customize it yourself?

Anyway keep up the excellent quality writing, it’s uncommon to see a great weblog like this one nowadays..

验证码