Home All Groups Group Topic Archive Search About

Screen Scraping a Password Protected Site

Author
12 Apr 2007 7:40 PM
apondu
I'm trying to screen scrape a site that requires a password.

I am using C#.Net, i am new to this and with the information available
around on the internet i just put tht information into the code.

But still i am not able to achieve what i want to.

I have posted the code which i have written, along with the site and
the userid ans password

Can someone take a look at the code and help with the information on
where i am going wrong and guide me across with the correct procedure.
and help to perform screen scrapping of the password word protected
site.

Thnaks for the help

Regards,
Govardhan.

My Code :



public void getContent()
        {
            UTF8Encoding utf  = new UTF8Encoding();

            string url = "http://www.bloglines.com/login";

            Uri uri = new Uri(url);

            string userName = "apo***@gmail.com";

            string userPassword = "password123";

            int port = 80;

            string proxyUserName = "";

            string proxyPassword = "";

            string proxyName = "";

            CookieCollection Cookies = new CookieCollection();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "POST";

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

        //    request.Credentials = new
NetworkCredential( userName,userPassword  );

            request.CookieContainer = new CookieContainer();

            request.AllowAutoRedirect = true;

            if (Cookies != null && Cookies.Count > 0)

                request.CookieContainer.Add(Cookies);

//  Code Changed to have post data

            string postData = "email=apo***@gmail.com&password=password123";
            byte[] postBytes = Encoding.UTF8.GetBytes (postData);

            Stream postStream = request.GetRequestStream();
            postStream.Write(postBytes, 0, postBytes.Length);
            postStream.Close();

//  End of  Code Changed to have post data

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

                        if (response.Cookies.Count > 0)
                        {
                            if (Cookies == null)

                            {
                                Cookies = response.Cookies;
                            }
                            else
                            {
                                // If we already have cookies update list

                                foreach (Cookie oRespCookie in    response.Cookies)
                                {
                                    bool bMatch = false;

                                    foreach(Cookie oReqCookie in Cookies)
                                    {
                                        if (oReqCookie.Name ==    oRespCookie.Name)
                                        {
                                            oReqCookie.Value =    oRespCookie.Name;

                                            bMatch = true;

                                            break;
                                        }
                                    }
                                    if (!bMatch)
                                        Cookies.Add(oRespCookie);
                                }

                            }
                        }  // End of response.Cookies.Count


            request.CookieContainer.Add(Cookies);

            request = (HttpWebRequest)WebRequest.Create("http://
www.bloglines.com/myblogs");

            response = (HttpWebResponse)request.GetResponse();

            Stream strm = response.GetResponseStream();

            System.Text.Encoding ec =
System.Text.Encoding.GetEncoding("utf-8");

            System.IO.StreamReader reader = new System.IO.StreamReader(strm,
ec);

            string str = reader.ReadToEnd();

            response.Close();
            strm.Close();
            reader.Close();

            FileStream fs = new FileStream("c:\
\q.htm",FileMode.Create,FileAccess.Write);

            StreamWriter sw = new StreamWriter(fs);

            sw.Write(str);

            sw.Close();
        }

Author
12 Apr 2007 8:07 PM
Peter Bromberg [C# MVP]
Apondu,
You just posted code with your Bloglines username and password on a public
newsgroup where any hacker can grab it and go mess up your account?
Come on, man.
Peter

Show quoteHide quote
"apondu" <apo***@gmail.com> wrote in message
news:1176406812.789669.82810@l77g2000hsb.googlegroups.com...
>
>
> I'm trying to screen scrape a site that requires a password.
>
> I am using C#.Net, i am new to this and with the information available
> around on the internet i just put tht information into the code.
>
> But still i am not able to achieve what i want to.
>
> I have posted the code which i have written, along with the site and
> the userid ans password
>
> Can someone take a look at the code and help with the information on
> where i am going wrong and guide me across with the correct procedure.
> and help to perform screen scrapping of the password word protected
> site.
>
> Thnaks for the help
>
> Regards,
> Govardhan.
>
> My Code :
>
>
>
> public void getContent()
> {
> UTF8Encoding utf  = new UTF8Encoding();
>
> string url = "http://www.bloglines.com/login";
>
> Uri uri = new Uri(url);
>
> string userName = "apo***@gmail.com";
>
> string userPassword = "password123";
>
> int port = 80;
>
> string proxyUserName = "";
>
> string proxyPassword = "";
>
> string proxyName = "";
>
> CookieCollection Cookies = new CookieCollection();
>
> HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
>
> request.Method = "POST";
>
> request.ContentType = "application/x-www-form-urlencoded";
>
> // request.Credentials = new
> NetworkCredential( userName,userPassword  );
>
> request.CookieContainer = new CookieContainer();
>
> request.AllowAutoRedirect = true;
>
> if (Cookies != null && Cookies.Count > 0)
>
> request.CookieContainer.Add(Cookies);
>
> //  Code Changed to have post data
>
> string postData = "email=apo***@gmail.com&password=password123";
> byte[] postBytes = Encoding.UTF8.GetBytes (postData);
>
> Stream postStream = request.GetRequestStream();
> postStream.Write(postBytes, 0, postBytes.Length);
> postStream.Close();
>
> //  End of  Code Changed to have post data
>
> HttpWebResponse response = (HttpWebResponse)request.GetResponse();
>
> if (response.Cookies.Count > 0)
> {
> if (Cookies == null)
>
> {
> Cookies = response.Cookies;
> }
> else
> {
> // If we already have cookies update list
>
> foreach (Cookie oRespCookie in response.Cookies)
> {
> bool bMatch = false;
>
> foreach(Cookie oReqCookie in Cookies)
> {
> if (oReqCookie.Name == oRespCookie.Name)
> {
> oReqCookie.Value = oRespCookie.Name;
>
> bMatch = true;
>
> break;
> }
> }
> if (!bMatch)
> Cookies.Add(oRespCookie);
> }
>
> }
> }  // End of response.Cookies.Count
>
>
> request.CookieContainer.Add(Cookies);
>
> request = (HttpWebRequest)WebRequest.Create("http://
> www.bloglines.com/myblogs");
>
> response = (HttpWebResponse)request.GetResponse();
>
> Stream strm = response.GetResponseStream();
>
> System.Text.Encoding ec =
> System.Text.Encoding.GetEncoding("utf-8");
>
> System.IO.StreamReader reader = new System.IO.StreamReader(strm,
> ec);
>
> string str = reader.ReadToEnd();
>
> response.Close();
> strm.Close();
> reader.Close();
>
> FileStream fs = new FileStream("c:\
> \q.htm",FileMode.Create,FileAccess.Write);
>
> StreamWriter sw = new StreamWriter(fs);
>
> sw.Write(str);
>
> sw.Close();
> }
>
Are all your drivers up to date? click for free checkup

Author
12 Apr 2007 11:13 PM
Alun Harford
Peter Bromberg [C# MVP] wrote:
> Apondu,
> You just posted code with your Bloglines username and password on a public
> newsgroup where any hacker can grab it and go mess up your account?
> Come on, man.
> Peter

Plausible deniability?
Or is his password not actually password123? :-)

Alun Harford
Author
13 Apr 2007 1:32 AM
PS
"Peter Bromberg [C# MVP]" <petebromberg@yahoo.nospammin.com> wrote in
message news:OLpfd4TfHHA.1816@TK2MSFTNGP06.phx.gbl...
> Apondu,
> You just posted code with your Bloglines username and password on a public
> newsgroup where any hacker can grab it and go mess up your account?
> Come on, man.
> Peter

That's not his real password.

PS

Show quoteHide quote
>
> "apondu" <apo***@gmail.com> wrote in message
> news:1176406812.789669.82810@l77g2000hsb.googlegroups.com...
>>
>>
>> I'm trying to screen scrape a site that requires a password.
>>
>> I am using C#.Net, i am new to this and with the information available
>> around on the internet i just put tht information into the code.
>>
>> But still i am not able to achieve what i want to.
>>
>> I have posted the code which i have written, along with the site and
>> the userid ans password
>>
>> Can someone take a look at the code and help with the information on
>> where i am going wrong and guide me across with the correct procedure.
>> and help to perform screen scrapping of the password word protected
>> site.
>>
>> Thnaks for the help
>>
>> Regards,
>> Govardhan.
>>
>> My Code :
>>
>>
>>
>> public void getContent()
>> {
>> UTF8Encoding utf  = new UTF8Encoding();
>>
>> string url = "http://www.bloglines.com/login";
>>
>> Uri uri = new Uri(url);
>>
>> string userName = "apo***@gmail.com";
>>
>> string userPassword = "password123";
>>
>> int port = 80;
>>
>> string proxyUserName = "";
>>
>> string proxyPassword = "";
>>
>> string proxyName = "";
>>
>> CookieCollection Cookies = new CookieCollection();
>>
>> HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
>>
>> request.Method = "POST";
>>
>> request.ContentType = "application/x-www-form-urlencoded";
>>
>> // request.Credentials = new
>> NetworkCredential( userName,userPassword  );
>>
>> request.CookieContainer = new CookieContainer();
>>
>> request.AllowAutoRedirect = true;
>>
>> if (Cookies != null && Cookies.Count > 0)
>>
>> request.CookieContainer.Add(Cookies);
>>
>> //  Code Changed to have post data
>>
>> string postData = "email=apo***@gmail.com&password=password123";
>> byte[] postBytes = Encoding.UTF8.GetBytes (postData);
>>
>> Stream postStream = request.GetRequestStream();
>> postStream.Write(postBytes, 0, postBytes.Length);
>> postStream.Close();
>>
>> //  End of  Code Changed to have post data
>>
>> HttpWebResponse response = (HttpWebResponse)request.GetResponse();
>>
>> if (response.Cookies.Count > 0)
>> {
>> if (Cookies == null)
>>
>> {
>> Cookies = response.Cookies;
>> }
>> else
>> {
>> // If we already have cookies update list
>>
>> foreach (Cookie oRespCookie in response.Cookies)
>> {
>> bool bMatch = false;
>>
>> foreach(Cookie oReqCookie in Cookies)
>> {
>> if (oReqCookie.Name == oRespCookie.Name)
>> {
>> oReqCookie.Value = oRespCookie.Name;
>>
>> bMatch = true;
>>
>> break;
>> }
>> }
>> if (!bMatch)
>> Cookies.Add(oRespCookie);
>> }
>>
>> }
>> }  // End of response.Cookies.Count
>>
>>
>> request.CookieContainer.Add(Cookies);
>>
>> request = (HttpWebRequest)WebRequest.Create("http://
>> www.bloglines.com/myblogs");
>>
>> response = (HttpWebResponse)request.GetResponse();
>>
>> Stream strm = response.GetResponseStream();
>>
>> System.Text.Encoding ec =
>> System.Text.Encoding.GetEncoding("utf-8");
>>
>> System.IO.StreamReader reader = new System.IO.StreamReader(strm,
>> ec);
>>
>> string str = reader.ReadToEnd();
>>
>> response.Close();
>> strm.Close();
>> reader.Close();
>>
>> FileStream fs = new FileStream("c:\
>> \q.htm",FileMode.Create,FileAccess.Write);
>>
>> StreamWriter sw = new StreamWriter(fs);
>>
>> sw.Write(str);
>>
>> sw.Close();
>> }
>>
>
>
Author
13 Apr 2007 4:40 AM
apondu
Show quote Hide quote
On Apr 13, 6:32 am, "PS" <ecneserpeg***@hotmail.com> wrote:
> "Peter Bromberg [C# MVP]" <petebromb...@yahoo.nospammin.com> wrote in
> messagenews:OLpfd4TfHHA.1***@TK2MSFTNGP06.phx.gbl...
>
> > Apondu,
> > You just posted code with your Bloglines username andpasswordon a public
> > newsgroup where any hacker can grab it and go mess up your account?
> > Come on, man.
> > Peter
>
> That's not his realpassword.
>
> PS
>
>
>
> > "apondu" <apo***@gmail.com> wrote in message
> >news:1176406812.789669.82810@l77g2000hsb.googlegroups.com...
>
> >> I'm trying toscreenscrape asitethat requires apassword.
>
> >> I am using C#.Net, i am new to this and with the information available
> >> around on the internet i just put tht information into the code.
>
> >> But still i am not able to achieve what i want to.
>
> >> I have posted the code which i have written, along with thesiteand
> >> the userid anspassword
>
> >> Can someone take a look at the code and help with the information on
> >> where i am going wrong and guide me across with the correct procedure.
> >> and help to performscreenscrapping of thepasswordwordprotected
> >>site.
>
> >> Thnaks for the help
>
> >> Regards,
> >> Govardhan.
>
> >> My Code :
>
> >> public void getContent()
> >> {
> >> UTF8Encoding utf  = new UTF8Encoding();
>
> >> string url = "http://www.bloglines.com/login";
>
> >> Uri uri = new Uri(url);
>
> >> string userName = "apo***@gmail.com";
>
> >> string userPassword = "password123";
>
> >> int port = 80;
>
> >> string proxyUserName = "";
>
> >> string proxyPassword = "";
>
> >> string proxyName = "";
>
> >> CookieCollection Cookies = new CookieCollection();
>
> >> HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
>
> >> request.Method = "POST";
>
> >> request.ContentType = "application/x-www-form-urlencoded";
>
> >> // request.Credentials = new
> >> NetworkCredential( userName,userPassword  );
>
> >> request.CookieContainer = new CookieContainer();
>
> >> request.AllowAutoRedirect = true;
>
> >> if (Cookies != null && Cookies.Count > 0)
>
> >> request.CookieContainer.Add(Cookies);
>
> >> //  Code Changed to have post data
>
> >> string postData = "email=apo***@gmail.com&password=password123";
> >> byte[] postBytes = Encoding.UTF8.GetBytes (postData);
>
> >> Stream postStream = request.GetRequestStream();
> >> postStream.Write(postBytes, 0, postBytes.Length);
> >> postStream.Close();
>
> >> //  End of  Code Changed to have post data
>
> >> HttpWebResponse response = (HttpWebResponse)request.GetResponse();
>
> >> if (response.Cookies.Count > 0)
> >> {
> >> if (Cookies == null)
>
> >> {
> >> Cookies = response.Cookies;
> >> }
> >> else
> >> {
> >> // If we already have cookies update list
>
> >> foreach (Cookie oRespCookie in response.Cookies)
> >> {
> >> bool bMatch = false;
>
> >> foreach(Cookie oReqCookie in Cookies)
> >> {
> >> if (oReqCookie.Name == oRespCookie.Name)
> >> {
> >> oReqCookie.Value = oRespCookie.Name;
>
> >> bMatch = true;
>
> >> break;
> >> }
> >> }
> >> if (!bMatch)
> >> Cookies.Add(oRespCookie);
> >> }
>
> >> }
> >> }  // End of response.Cookies.Count
>
> >> request.CookieContainer.Add(Cookies);
>
> >> request = (HttpWebRequest)WebRequest.Create("http://
> >>www.bloglines.com/myblogs");
>
> >> response = (HttpWebResponse)request.GetResponse();
>
> >> Stream strm = response.GetResponseStream();
>
> >> System.Text.Encoding ec =
> >> System.Text.Encoding.GetEncoding("utf-8");
>
> >> System.IO.StreamReader reader = new System.IO.StreamReader(strm,
> >> ec);
>
> >> string str = reader.ReadToEnd();
>
> >> response.Close();
> >> strm.Close();
> >> reader.Close();
>
> >> FileStream fs = new FileStream("c:\
> >> \q.htm",FileMode.Create,FileAccess.Write);
>
> >> StreamWriter sw = new StreamWriter(fs);
>
> >> sw.Write(str);
>
> >> sw.Close();
> >> }

hi,

i changed my password, can any of u know hw to achieve wht i a trying
to ... Help me out if anyone knows abt it...

Regards,
Govardhan.

Bookmark and Share