473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Screen Scraping a Password Protected Site



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 = "ap****@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=ap****@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();
}

Apr 12 '07 #1
0 1791

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Roland Hall | last post by:
Am I correct in assuming screen scraping is just the response text sent to the browser? If so, would that mean that this could not be screen scraped? function moi() { var tag = '<a href='; var...
0
by: Robert Martinez | last post by:
I've seen a lot about screen scraping with .NET, mostly in VB.net. I have been able to convert most of it over, but it is still just very basic stuff. Can someone help direct me toward some good...
14
by: n8 | last post by:
Hi, Hi have to do the followign and have been racking my brain with various solutions that have had no so great results. I want to use the System.Net.WebClient to submit data to a form (log a...
4
by: rachel | last post by:
Hello, I am currently contracted out by a real estate agent. He has a page that he has created himself that has a list of homes.. their images and data in html format. He wants me to take...
2
by: Victor | last post by:
I'm doing screen scraping by retrieving data from one site and entering into another site. I have a problem with logging into the site. User name and password field contain 'name' property, and...
2
by: Victor | last post by:
Hi, I have a problem with logging into web site via screen scraping. User name and password field contain 'name' property, and therefore I can easily do assignment to them:...
0
by: Steve | last post by:
I am working on an application to screen scrape information from a web page. I have the base code working but the problem is I have to login before I can get the info I need. The page is hosted on...
2
by: Alan Silver | last post by:
Hello, I would like to pull some information off a site that requires a log in. I have a subscription to a premium content site, and I would like to be able to do a few automatic requests...
4
by: apondu | last post by:
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...
1
by: ashwiniappajigowda | last post by:
Hi, I have an simple MFC dialog based application. On launch of that application 'Password protected screen saver' is not getting activated after the screen saver timeout. If 'On resume,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.