php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)分享


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);
?>

—-想了解更多的php相关异常处理怎么解决关注<猴子技术宅>



本文来自网络收集,不代表猴子技术宅立场,如涉及侵权请点击右边联系管理员删除。

如若转载,请注明出处:https://www.ssfiction.com/phpjc/84437.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注

评论列表(40条)

  • free watch xxx
    free watch xxx 2020年4月27日 下午10:54

    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

  • dominoqq Online
    dominoqq Online 2020年5月1日 上午5:00

    If you would like to grow your know-how just keep visiting this web page and be updated with the newest news posted here.

  • idn poker
    idn poker 2020年5月1日 下午5:07

    It’s an remarkable post in support of all the web users; they will take benefit from it I am sure.

  • microgaming casino
    microgaming casino 2020年5月2日 上午4:37

    Thankfulness to my father who stated to me on the topic of this web site, this website is really remarkable.

  • apk
    apk 2020年5月3日 下午3:36

    If you desire to take a great deal from this paragraph then you have to apply these strategies to your won webpage.

  • حواله یوان
    حواله یوان 2020年5月4日 下午2:43

    I am genuinely grateful to the holder of this web page who has shared this impressive paragraph at here.

  • playground
    playground 2020年5月5日 上午4:18

    I am regular reader, how are you everybody?
    This article posted at this website is actually fastidious.

  • judi
    judi 2020年5月5日 上午5:34

    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.

  • slot online uang asli
    slot online uang asli 2020年5月5日 上午10:43

    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!

  • tiktok fans
    tiktok fans 2020年5月5日 下午4:20

    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.

  • telefonu
    telefonu 2020年5月7日 下午7:39

    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.

  • Brazilian
    Brazilian 2020年5月8日 下午9:11

    Greetings! Very helpful advice in this particular article!

    It is the little changes that will make the biggest changes.
    Many thanks for sharing!

  • 猴子在天上飞
    猴子游戏编程 2020年5月9日 上午9:36

    Just maintain the server!Being Fearless

  • Takimi
    Takimi 2020年5月10日 上午12:22

    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.

  • playground
    playground 2020年5月10日 上午10:28

    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?

  • endriejav
    endriejav 2020年5月11日 上午1:40

    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!

  • Gulo
    Gulo 2020年5月11日 上午1:52

    Asking questions are really good thing if you are
    not understanding anything fully, however this article offers nice understanding even.

  • situs
    situs 2020年5月11日 上午5:10

    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?

  • pbun
    pbun 2020年5月11日 下午7:56

    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?

  • no
    no 2020年5月12日 上午8:35

    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!

  • ment
    ment 2020年5月12日 上午10:16

    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.

  • Takimi
    Takimi 2020年5月13日 上午2:04

    Pretty! This was an extremely wonderful post.

    Thankk you for providing this info.

  • escort
    escort 2020年5月13日 上午2:41

    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

  • casa
    casa 2020年5月13日 下午11:58

    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!

  • Nargile
    Nargile 2020年5月14日 上午7:04

    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.

  • judi
    judi 2020年5月14日 下午5:43

    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!

  • 匿名
    匿名 2020年5月15日 上午3:50

    It’s amazing in support of me to have a web page, which is valuable in favor of my know-how.
    thanks admin

  • 匿名
    匿名 2020年5月15日 下午8:15

    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.

  • age
    age 2020年5月16日 上午4:22

    Pretty! This has been a really wonderful post. Thanks for
    providing this information.

  • home
    home 2020年5月16日 上午5:39

    Everything is very open with a really clear
    clarification of the issues. It was definitely informative.
    Your site is very useful. Thanks for sharing!

  • Viagra
    Viagra 2020年5月17日 下午9:03

    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!

  • 匿名
    匿名 2020年5月18日 下午9:34

    This piece of writing will help the internet people
    for building up new blog or even a weblog from
    start to end.

  • online
    online 2020年5月19日 上午10:23

    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.

  • dried jackfruit exporter
    dried jackfruit exporter 2020年5月21日 下午3:59

    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.

  • sli
    sli 2020年5月26日 上午9:59

    It’s fantastic that you are getting thoughts from this post as well as from
    our dialogue made at this place.

  • rket
    rket 2020年5月27日 下午5:56

    Thanks for any other magnificent article.

  • lig
    lig 2020年5月28日 上午7:47

    What’s up, yup this article is actually nice and I have learned lot
    of things from it on the topic of blogging. thanks.

  • drumdeals
    drumdeals 2020年5月29日 下午6:23

    Hello, everything is going sound here and ofcourse every one is sharing data,
    that’s actually excellent, keep up writing.

  • php curl
    php curl 2020年6月2日 上午12:27

    bookmarked!!, I really like your blog!php curl 登录163邮箱并抓取邮箱好友列表的代码(经测试)分享