473,666 Members | 2,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.c om/login";

Uri uri = new Uri(url);

string userName = "ap****@gmail.c om";

string userPassword = "password12 3";

int port = 80;

string proxyUserName = "";

string proxyPassword = "";

string proxyName = "";

CookieCollectio n Cookies = new CookieCollectio n();

HttpWebRequest request = (HttpWebRequest )WebRequest.Cre ate(url);

request.Method = "POST";

request.Content Type = "applicatio n/x-www-form-urlencoded";

// request.Credent ials = new
NetworkCredenti al( userName,userPa ssword );

request.CookieC ontainer = new CookieContainer ();

request.AllowAu toRedirect = true;

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

request.CookieC ontainer.Add(Co okies);

// Code Changed to have post data

string postData = "email=ap****@g mail.com&passwo rd=password123" ;
byte[] postBytes = Encoding.UTF8.G etBytes (postData);

Stream postStream = request.GetRequ estStream();
postStream.Writ e(postBytes, 0, postBytes.Lengt h);
postStream.Clos e();

// End of Code Changed to have post data

HttpWebResponse response = (HttpWebRespons e)request.GetRe sponse();

if (response.Cooki es.Count 0)
{
if (Cookies == null)

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

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

foreach(Cookie oReqCookie in Cookies)
{
if (oReqCookie.Nam e == oRespCookie.Nam e)
{
oReqCookie.Valu e = oRespCookie.Nam e;

bMatch = true;

break;
}
}
if (!bMatch)
Cookies.Add(oRe spCookie);
}

}
} // End of response.Cookie s.Count
request.CookieC ontainer.Add(Co okies);

request = (HttpWebRequest )WebRequest.Cre ate("http://
www.bloglines.c om/myblogs");

response = (HttpWebRespons e)request.GetRe sponse();

Stream strm = response.GetRes ponseStream();

System.Text.Enc oding ec =
System.Text.Enc oding.GetEncodi ng("utf-8");

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

string str = reader.ReadToEn d();

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

FileStream fs = new FileStream("c:\
\q.htm",FileMod e.Create,FileAc cess.Write);

StreamWriter sw = new StreamWriter(fs );

sw.Write(str);

sw.Close();
}

Apr 12 '07 #1
0 1803

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

Similar topics

4
5732
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 tagType1 = '"mail'+'to:', tagType2 = '">', tagType3 = '<\/a>'; var user1 = 'web', user2 = 'master', user3 = '@'; var dom1 = 'danger', dom2 = 'ous', dom3 = 'ly'; var tld = '.us';...
0
2155
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 info / samples on the following: I want to be able to do 3 things: 1) Set up a module in IBUYSPY Portal (like in the right or left pane) that simply just scrapes headlines from certain sites. 2) Allow users to set up scraping of certain sites...
14
7880
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 user in) and then redirect to the correct article. Here is the scenerio. If you are not logged into the site for certain articles you are
4
3452
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 this page and reformat it so that it looks different. Do I use screen scraping to do this? Could someone please point me to a good screen scraping
2
1515
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 therefore I can easily do assign statement to them. "userid=uidTest&password=pwTest" However, submit button represented on page via hyper link: <A href="javascript:login()" onBlur ="foc()"><IMG align=middle border=0 height=15...
2
6666
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: "userid=uidTest&password=pwTest" However, submit button represented on page via hyper link: <A href="javascript:login()" onBlur ="foc()"><IMG align=middle border=0 height=15 src="images/submit.gif" width=64></A>
0
3647
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 my Router. When I go to the IP of the router I get the following page. <HTML> <head> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> <title>Login</title> </head>
2
1727
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 instead of having to load the site manually in a browser. I have seen plenty articles that explain how to do screen scraping in ..NET, others that describe how to do it via a POST, but I couldn't find any that covered my scenario.
4
5129
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 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
1
2373
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, password protect' option unchecked, I am getting the Screen saver. Application not generating any of the keyboard or any user events to
0
8444
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4368
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1775
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.