Okay, I'm trying to scrape information from a Motorola product and am having trouble posting to authenticate to it and then moving on from there.
I've modified some sample screen scrape code and POST examples, but I just don't get it. So here is the information from the device and then the code I'm using.
The URL of the login page is
The URL I end up at after logging in is
I'm almost there, but I don't quite have the code working.
Here is the page source of the login page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<html xmlns=" lang="en" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="_canopy.css" media="screen" />
<link rel="stylesheet" type="text/css" href="_canopypda.css" media="handheld" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>Log In</title>
</head>
<body>
<!-- Insert Logo Here -->
<!-- Use Argument -->
<div class='logo'><img class='logo' src='_canopy.jpg' alt='Logo' /></div>
<table id="frame">
<tr><td class="menu">
<div id="menu">
<div id="loginmenu" >
<a class="menu" href="main.cgi?mac_esn=0a003ef22754">Back to Main Page</a>
</div>
</div>
</td>
<td id="tabandpage">
<div id="page">
<h1>Log In</h1>
<h2>5.7GHz - Subscriber Module - 0a-00-3e-f2-27-54 </h2>
<div class="section">
<h2 class="sectiontitle">Log In</h2>
<p>Please login into the system</p>
<form action="login.cgi" method="post">
<p>
Username: <input type="text" name="CanopyUsername" /><br/>
Password: <input type="password" name="CanopyPassword" /><br/>
</p>
<div class="buttons">
<input type="submit" value="Ok" name="ok" />
<input type="reset" value="Cancel" />
</div>
</form>
</div>
</div>
</td>
</tr>
</table>
</body>
</html>
CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E)
{
String text = readHtmlPage(" }
private String readHtmlPage(string url)
{
String result = "";
String strPost = "CanopyUsername=User&CanopyPassword=password&Ok=ok";
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally {
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
</script>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
I've modified some sample screen scrape code and POST examples, but I just don't get it. So here is the information from the device and then the code I'm using.
The URL of the login page is
The URL I end up at after logging in is
I'm almost there, but I don't quite have the code working.
Here is the page source of the login page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "<html xmlns=" lang="en" xml:lang="en">
<head>
<link rel="stylesheet" type="text/css" href="_canopy.css" media="screen" />
<link rel="stylesheet" type="text/css" href="_canopypda.css" media="handheld" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>Log In</title>
</head>
<body>
<!-- Insert Logo Here -->
<!-- Use Argument -->
<div class='logo'><img class='logo' src='_canopy.jpg' alt='Logo' /></div>
<table id="frame">
<tr><td class="menu">
<div id="menu">
<div id="loginmenu" >
<a class="menu" href="main.cgi?mac_esn=0a003ef22754">Back to Main Page</a>
</div>
</div>
</td>
<td id="tabandpage">
<div id="page">
<h1>Log In</h1>
<h2>5.7GHz - Subscriber Module - 0a-00-3e-f2-27-54 </h2>
<div class="section">
<h2 class="sectiontitle">Log In</h2>
<p>Please login into the system</p>
<form action="login.cgi" method="post">
<p>
Username: <input type="text" name="CanopyUsername" /><br/>
Password: <input type="password" name="CanopyPassword" /><br/>
</p>
<div class="buttons">
<input type="submit" value="Ok" name="ok" />
<input type="reset" value="Cancel" />
</div>
</form>
</div>
</div>
</td>
</tr>
</table>
</body>
</html>
CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns=" >
<head runat="server">
<title>Untitled Page</title>
</head>
<script language="C#" runat="server">
void Page_Load(Object Src, EventArgs E)
{
String text = readHtmlPage(" }
private String readHtmlPage(string url)
{
String result = "";
String strPost = "CanopyUsername=User&CanopyPassword=password&Ok=ok";
StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally {
myWriter.Close();
}
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr =
new StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
</script>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>