Technology, Smartphones, Games


Web Scraping Yahoo Mail

This code will help you to screen scrap or web scrap yahoo mail. Replace the uservame and password with your user name and password.

It is recomended that whenever you copy and paste some code from some sites you just go through that ,because there may be some tricks which will take your user name and password to the author. Here there is no such code. But still have a check and learn the code.

For web scraping  replace the links to your page and  handle it, there you will not have to login every time. Just diclare the "cookieContainer" as global and call the function GetPage for the pages you got after login If you have any doubt you are free to ask. If you need more explanation of the codes i will add that.  So respond to the post if you need any help .Here is the code

protected void Page_Load(object sender, EventArgs e)

{

Response.Write(FormLoginGet("https://login.yahoo.com/config/login?",

".tries=1&.src=ym&.md5=&.hash=&.js=&.last=&promo=&.intl=us

&.bypass=&.partner=&.u=b78hrnt3na3lq&.v=0&.challenge=xvOEB.4fkvYjRArHUoONYy78AKM.

&.yplus=&.emailCode=&pkg=&stepid=&.ev=&hasMsgr=1&.chkP=Y&.pd=ym_ver%3d0%26c%3d

&login=UserName&passwd=Password&.save=Sign+In", "http://in.f534.mail.yahoo.com/ym/login"));

}

private static string FormLoginGet(string loginUri, string loginData, string requestUri)

{

// cookieContainer is used to store the cookies used by the login

CookieContainer cookieContainer = new CookieContainer();

// First hit the login page

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(loginUri);

req.CookieContainer = cookieContainer;

req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";

ASCIIEncoding encoding = new ASCIIEncoding();

byte[] loginDataBytes = encoding.GetBytes(loginData);

req.ContentLength = loginDataBytes.Length;

Stream stream = req.GetRequestStream();

stream.Write(loginDataBytes, 0, loginDataBytes.Length);

stream.Close();

HttpWebResponse res = (HttpWebResponse)req.GetResponse();

// Then grab the content of the desired page

req = (HttpWebRequest)HttpWebRequest.Create(requestUri);

req.CookieContainer = cookieContainer;

req.Method = "GET";

res = (HttpWebResponse)req.GetResponse();

StreamReader sr = new StreamReader(res.GetResponseStream());

return sr.ReadToEnd();

}

private string getPage(string requestUri)

{

try

{

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(requestUri);

req.CookieContainer = cookieContainer;

req.Method = "GET";

HttpWebResponse res = (HttpWebResponse)req.GetResponse();

StreamReader sr = new StreamReader(res.GetResponseStream());

return sr.ReadToEnd();

}

catch (Exception exp)

{

return (exp.Message.ToString());

}

}