CURL技术说白了就是模拟浏览器的动作实现页面抓取或表单提交,通过此技术可以实现许多有去的功能。
代码如下:
<?php
error_reporting(0);
//邮箱用户名(不带@163.com后缀的)
$user = ‘papatata_test’;
//邮箱密码
$pass = ‘000000’;
//目标邮箱
//$mail_addr = uenucom@163.com’;
//登陆
$url = ‘http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1’;
$ch = curl_init($url);
//创建一个用于存放cookie信息的临时文件
$cookie = tempnam(‘.’,’~’);
$referer_login = ‘http://mail.163.com’;
//返回结果存放在变量中,而不是默认的直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_REFERER, $referer_login);
$fields_post = array(
‘username’=> $user,
‘password’=> $pass,
‘verifycookie’=>1,
‘style’=>-1,
‘product’=> ‘mail163’,
‘selType’=>-1,
‘secure’=>’on’
);
$headers_login = array(
‘User-Agent’ => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0’,
‘Referer’ => ‘http://www.163.com’
);
$fields_string = ”;
foreach($fields_post as $key => $value)
{
$fields_string .= $key . ‘=’ . $value . ‘&’;
}
$fields_string = rtrim($fields_string , ‘&’);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
//关闭连接时,将服务器端返回的cookie保存在以下文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$result= curl_exec($ch);
curl_close($ch);
//跳转
$url=’http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=loki_wuxi’;
$ch = curl_init($url);
$headers = array(
‘User-Agent’ => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0’
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//将之前保存的cookie信息,一起发送到服务器端
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//取得sid
preg_match(‘/sid=[^”].*/’, $result, $location);
$sid = substr($location[0], 4, -1);
//file_put_contents(‘./result.txt’, $sid);
//通讯录地址
$url=’http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid=’.$sid.’&gid=all’;
$ch = curl_init($url);
$headers = array(
‘User-Agent’ => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0’
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//file_put_contents(‘./result.txt’, $result);
unlink($cookie);
//开始抓取内容
preg_match_all(‘/<td class=”Ibx_Td_addrName”><a[^>]*>(.*?)</a></td><td class=”Ibx_Td_addrEmail”><a[^>]*>(.*?)</a></td>/i’, $result,$infos,PREG_SET_ORDER);
//1:姓名2:邮箱
print_r($infos);
?>
error_reporting(0);
//邮箱用户名(不带@163.com后缀的)
$user = ‘papatata_test’;
//邮箱密码
$pass = ‘000000’;
//目标邮箱
//$mail_addr = uenucom@163.com’;
//登陆
$url = ‘http://reg.163.com/logins.jsp?type=1&url=http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight%3D1%26verifycookie%3D1%26language%3D-1%26style%3D-1’;
$ch = curl_init($url);
//创建一个用于存放cookie信息的临时文件
$cookie = tempnam(‘.’,’~’);
$referer_login = ‘http://mail.163.com’;
//返回结果存放在变量中,而不是默认的直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_REFERER, $referer_login);
$fields_post = array(
‘username’=> $user,
‘password’=> $pass,
‘verifycookie’=>1,
‘style’=>-1,
‘product’=> ‘mail163’,
‘selType’=>-1,
‘secure’=>’on’
);
$headers_login = array(
‘User-Agent’ => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0’,
‘Referer’ => ‘http://www.163.com’
);
$fields_string = ”;
foreach($fields_post as $key => $value)
{
$fields_string .= $key . ‘=’ . $value . ‘&’;
}
$fields_string = rtrim($fields_string , ‘&’);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
//关闭连接时,将服务器端返回的cookie保存在以下文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_login);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
$result= curl_exec($ch);
curl_close($ch);
//跳转
$url=’http://entry.mail.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=-1&username=loki_wuxi’;
$ch = curl_init($url);
$headers = array(
‘User-Agent’ => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0’
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//将之前保存的cookie信息,一起发送到服务器端
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//取得sid
preg_match(‘/sid=[^”].*/’, $result, $location);
$sid = substr($location[0], 4, -1);
//file_put_contents(‘./result.txt’, $sid);
//通讯录地址
$url=’http://g4a30.mail.163.com/jy3/address/addrlist.jsp?sid=’.$sid.’&gid=all’;
$ch = curl_init($url);
$headers = array(
‘User-Agent’ => ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9) Gecko/2008052906 Firefox/3.0’
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
$result = curl_exec($ch);
curl_close($ch);
//file_put_contents(‘./result.txt’, $result);
unlink($cookie);
//开始抓取内容
preg_match_all(‘/<td class=”Ibx_Td_addrName”><a[^>]*>(.*?)</a></td><td class=”Ibx_Td_addrEmail”><a[^>]*>(.*?)</a></td>/i’, $result,$infos,PREG_SET_ORDER);
//1:姓名2:邮箱
print_r($infos);
?>
—-想了解更多的php相关异常处理怎么解决关注<猴子技术宅>
”
本文来自网络收集,不代表猴子技术宅立场,如涉及侵权请点击右边联系管理员删除。
如若转载,请注明出处:https://www.ssfiction.com/phpjc/84437.html
评论列表(40条)
Excellent weblog right here! Additionally your site rather a lot
up very fast! What host are you using? Can I get
your affiliate link on your host? I wish my web site loaded up as quickly as yours lol
@free watch xxx:aliyun
If you would like to grow your know-how just keep visiting this web page and be updated with the newest news posted here.
It’s an remarkable post in support of all the web users; they will take benefit from it I am sure.
Thankfulness to my father who stated to me on the topic of this web site, this website is really remarkable.
If you desire to take a great deal from this paragraph then you have to apply these strategies to your won webpage.
I am genuinely grateful to the holder of this web page who has shared this impressive paragraph at here.
I am regular reader, how are you everybody?
This article posted at this website is actually fastidious.
Hi there! Do you use Twitter? I’d like to follow you if
that would be okay. I’m absolutely enjoying your blog and look forward to new
updates.
I was recommended this blog by my cousin. I am not sure whether this post is written by him as nobody
else know such detailed about my trouble. You are wonderful!
Thanks!
I do agree with all of the concepts you’ve introduced on your post.
They are very convincing and will certainly work.
Nonetheless, the posts are very quick for starters. May you please
prolong them a bit from next time? Thanks for the post.
I loved as much as you’ll receive carried out right here.
The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get got an nervousness 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 hike.
Greetings! Very helpful advice in this particular article!
It is the little changes that will make the biggest changes.
Many thanks for sharing!
Just maintain the server!Being Fearless
You can definitely see your skills in the article you write.
The arena holes for even more passionate riters like youu who aren’t afraid to say how they believe.
At all times goo after your heart.
Remarkable things here. I’m very glad to peer your article.
Thank you so much and I am having a look forward to contact you.
Will you please drop me a e-mail?
Somebody essentially assist to make significantly posts I’d state.
That is the very first time I frequented your web page and to this point?
I surprised with the analysis you made to make this particular publish incredible.
Great process!
Asking questions are really good thing if you are
not understanding anything fully, however this article offers nice understanding even.
I’m really enjoying the theme/design of your weblog. Do you ever run into any browser compatibility problems?
A couple of my blog audience have complained about my site not operating correctly in Explorer but looks
great in Safari. Do you have any recommendations to help fix this issue?
Awesome things here. I’m very glad to see your article.
Thank you so much and I am having a look forward to touch
you. Will you kindly drop me a mail?
Wow, marvelous weblog layout! How lengthy have you been blogging for?
you made blogging glance easy. The total look of your web site is great, let alone
the content!
Your mode of describing the whole thing in this paragraph is in fact fastidious, all be
capable of effortlessly be aware of it, Thanks a lot.
Pretty! This was an extremely wonderful post.
Thankk you for providing this info.
I’m not that much of a online reader to be honest but
your blogs really nice, keep it up! I’ll go ahead and bookmark
your website to come back later. Cheers
I do not еven understand how I endeɗ uρ һere, but I assumed thhis ssubmit ѡas once greɑt.
Ι dоn’t understand ѡho you might be however certainly you are goіng to a famous
blogger ᴡhen yoᥙ аre not already. Cheers!
I think the admin of this web site is truly working hard in favor of his
website, as here every information is quality based data.
I was recommended this blog by my cousin. I am now
not positive whether this submit is written through him as no one
else recognise such exact about my problem. You are wonderful!
Thanks!
It’s amazing in support of me to have a web page, which is valuable in favor of my know-how.
thanks admin
Thanks for any other informative blog. Where else could I get that type of information written in such
an ideal method? I’ve a venture that I am simply
now working on, and I have been at the look out for such information.
Pretty! This has been a really wonderful post. Thanks for
providing this information.
Everything is very open with a really clear
clarification of the issues. It was definitely informative.
Your site is very useful. Thanks for sharing!
I do not even know how I ended up here, but I thought this post was great.
I don’t know who you are but certainly you’re going to a famous blogger
if you are not already 😉 Cheers!
This piece of writing will help the internet people
for building up new blog or even a weblog from
start to end.
I’ve been browsing online more than three hours today,
yet I never found any interesting article like yours.
It’s pretty worth enough for me. Personally, if all site owners and bloggers made good content as you did, the internet
will be much more useful than ever before.
Hi, I do think this is an excellent blog. I stumbledupon it ;
) I will return once again since i have saved as a favorite it.
Money and freedom is the best way to change, may you
be rich and continue to guide other people.
It’s fantastic that you are getting thoughts from this post as well as from
our dialogue made at this place.
Thanks for any other magnificent article.
What’s up, yup this article is actually nice and I have learned lot
of things from it on the topic of blogging. thanks.
Hello, everything is going sound here and ofcourse every one is sharing data,
that’s actually excellent, keep up writing.
bookmarked!!, I really like your blog!php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)分享