获取雅虎联系人 [英] To get contacts of yahoo

查看:79
本文介绍了获取雅虎联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想与Yahoo取得联系

Hi

I want to get contacts of yahoo

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Text;
using System.Collections.Specialized;
namespace WebApplication3
{
    public partial class WebForm1 : System.Web.UI.Page
    {
          private const string _addressBookUrl = "http://address.yahoo.com/yab/us/Yahoo_ab.csv?loc=us&.rand=1671497644&A=H&Yahoo_ab.csv";           private const string _authUrl = "https://login.yahoo.com/config/login?";  
         private const string _loginPage = "https://login.yahoo.com/config/login";  
         private const string _userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3"; 
        protected void Page_Load(object sender, EventArgs e)
        {
   //      string username=TextBox1.Text.ToString();
    //   string password= TextBox2.Text.ToString();
            
        } 
       

        protected void Button1_Click(object sender, EventArgs e)
       {  
           
 
                MailContactList      list = new MailContactList();  
   
             
                 WebClient webClient = new WebClient();  
                 webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;  
                 webClient.Encoding = Encoding.UTF8;  
   
                 byte[] firstResponse = webClient.DownloadData( _loginPage );  
                 string firstRes = Encoding.UTF8.GetString( firstResponse );  
   
   
                 NameValueCollection postToLogin = new NameValueCollection();  
                 Regex regex = new Regex( "type=\"hidden\" name=\"(.*?)\" value=\"(.*?)\"", RegexOptions.IgnoreCase );  
                 Match match = regex.Match( firstRes );  
                 while ( match.Success )  
                 {  
                     if ( match.Groups[ 0 ].Value.Length > 0 )  
                     {  
                         postToLogin.Add( match.Groups[ 1 ].Value, match.Groups[ 2 ].Value );  
                     }  
                     match = regex.Match( firstRes, match.Index + match.Length );  
                 }  
   
   
                 postToLogin.Add( ".save", "Sign In" );  
                 postToLogin.Add( ".persistent", "y" );  
   
                // string login = credential.UserName.Split( ''@'' )[ 0 ];  
                 postToLogin.Add( "login", "ANY EMAIL ADDRESS" );  //IN THIS PLEASE INSERT YOUR YAHOO EMAIL ADRESS
                 postToLogin.Add( "passwd", "SOME PASSWORD" );      //IN THIS PLEASE YOUR PASSWORD
   
                 webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;  
                 webClient.Headers[ HttpRequestHeader.Referer ] = _loginPage;  
                 webClient.Encoding = Encoding.UTF8;  
                 webClient.Headers[ HttpRequestHeader.Cookie ] = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];  
   
                 webClient.UploadValues( _authUrl, postToLogin );  
            string cookie = webClient.ResponseHeaders[ HttpResponseHeader.SetCookie ];  
   
                 if ( string.IsNullOrEmpty( cookie ) )  
                 {  
                      
                 }  
   
                 string newCookie = string.Empty;
               //  string[] tmp1 = cookie.Split();
                 string[] tmp1 = cookie.Split( '','' );  
                 foreach ( string var in tmp1 )  
                 {  
                     string[] tmp2 = var.Split( '';'' );  
                     newCookie = String.IsNullOrEmpty( newCookie ) ? tmp2[ 0 ] : newCookie + ";" + tmp2[ 0 ];  
                 }  
   
                 // set login cookie  
                 webClient.Headers[ HttpRequestHeader.Cookie ] = newCookie;  
                 byte[] thirdResponse = webClient.DownloadData( _addressBookUrl );  
                 string thirdRes = Encoding.UTF8.GetString( thirdResponse );  
   
                 string crumb = string.Empty;  
                 Regex regexCrumb = new Regex( "type=\"hidden\" name=\"\\.crumb\" id=\"crumb1\" value=\"(.*?)\"", RegexOptions.IgnoreCase );  
                 match = regexCrumb.Match( thirdRes );  
                 if ( match.Success && match.Groups[ 0 ].Value.Length > 0 )  
                 {  
                     crumb = match.Groups[ 1 ].Value;  
                 }  
   
                 NameValueCollection postDataAB = new NameValueCollection();  
                 postDataAB.Add( ".crumb", crumb );  
                 postDataAB.Add( "vcp", "import_export" );  
                 postDataAB.Add( "submit[action_export_yahoo]", "Export Now" );  
   
                 webClient.Headers[ HttpRequestHeader.UserAgent ] = _userAgent;  
            webClient.Headers[ HttpRequestHeader.Referer ] = _addressBookUrl;  
   
                 byte[] FourResponse = webClient.UploadValues( _addressBookUrl, postDataAB );  
                 string csvData = Encoding.UTF8.GetString( FourResponse );  
   
                string[] lines = csvData.Split( ''\n'' );  
            foreach ( string line in lines )  
                 {  
                     string[] items = line.Split( '','' );  
                     if ( items.Length < 5 )  
                     {  
                         continue;  
                     }  
                     string email = items[ 4 ];  
                     string name = items[ 3 ];  
                     if ( !string.IsNullOrEmpty( email ) && !string.IsNullOrEmpty( name ) )  
                     {  
                         email = email.Trim( ''\"'' );  
                         name = name.Trim( ''\"'' );  
                         if ( !email.Equals( "Email" ) && !name.Equals( "Nickname" ) )  
                         {  
                             MailContact mailContact = new MailContact();  
                             mailContact.Name = name;  
                             mailContact.Email = email;  
            
                             list.Add( mailContact );  
                         }  
                     }  
                 }  
   
                 
             }  
           
         }  
    
}


这是我的代码,但是我在
中得不到正确的输出


This is my code but i am not getting right output in

mailContact.Name = name;
 mailContact.Email = email;


请任何人帮我
在此先感谢

[edit]删除了SHOUTING,添加了代码块-OriginalGriff [/edit]


Please any one help me
Thanks in advance

[edit]SHOUTING removed, Code block added - OriginalGriff[/edit]

推荐答案

这是一个无用的问题.您发布了大量代码,并说您没有得到正确的输出".那你得到什么呢?你想要什么?有什么问题?
This is a useless question. You post a ton of code and say you don''t get ''right output''. What do you get then ? What were you hoping for ? What is the issue ?


这篇关于获取雅虎联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆