Click here to Skip to main content
15,909,827 members
Home / Discussions / C#
   

C#

 
AnswerRe: Release Photo Pin
Hum Dum25-Aug-09 19:55
Hum Dum25-Aug-09 19:55 
QuestionRe: Release Photo Pin
sanforjackass25-Aug-09 20:10
sanforjackass25-Aug-09 20:10 
AnswerRe: Release Photo Pin
Hum Dum25-Aug-09 20:18
Hum Dum25-Aug-09 20:18 
QuestionRe: Release Photo Pin
sanforjackass25-Aug-09 20:29
sanforjackass25-Aug-09 20:29 
QuestionRe: Release Photo Pin
sanforjackass25-Aug-09 20:52
sanforjackass25-Aug-09 20:52 
AnswerRe: Release Photo Pin
Henry Minute25-Aug-09 21:59
Henry Minute25-Aug-09 21:59 
GeneralRe: Release Photo Pin
sanforjackass26-Aug-09 2:16
sanforjackass26-Aug-09 2:16 
QuestionHelp needed with simple Web Spider Code Pin
manormi125-Aug-09 16:02
manormi125-Aug-09 16:02 
Hi folks I know there are lots of different free ones out there.
But I wanted to have a go at somthing quick as a learning exercise.

I got as far as the code below, but am having trouble putting found URL's (i.e. 'eachLineValue') from a web page back into the WebRequest.Create(URL)

Do i need some sort of function around this that I can call recursively with different URL's ?

thanks Mark

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;


namespace ShoppingDataExtractor
{
public partial class spider : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// used to build entire input
StringBuilder sb = new StringBuilder();

// used on each read operation
byte[] buf = new byte[8192];

string initialURL = "http://www.bestpricedirectory.com.au/";

try
{
WebRequest myRequest = WebRequest.Create(initialURL);

// Return the response.
WebResponse myResponse = myRequest.GetResponse();

Response.Write(myResponse);
// Code to use the WebResponse goes here.

Stream resStream = myResponse.GetResponseStream();

string tempString = null;
int count = 0;

do
{
// fill the buffer with data
count = resStream.Read(buf, 0, buf.Length);

// make sure we read some data
if (count != 0)
{
// translate from bytes to ASCII text
tempString = Encoding.ASCII.GetString(buf, 0, count);

// continue building the string
sb.Append(tempString);
}
}
while (count > 0); // any more data to read?


Response.Write(sb.ToString());

// regex to find all html links

// next - to use recursion to follow all links and write out


Regex r = new Regex(@"href=\""(.*?)\""",

RegexOptions.IgnoreCase | RegexOptions.Compiled);

MatchCollection matches = r.Matches(sb.ToString());

foreach (Match match in matches)
{
Array values = match.Value.ToCharArray();

foreach (System.Char line in values)
{
//Response.Write("{0} ", line);
File.AppendAllText(@"C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/Projects/ShoppingDataExtractor/spider.txt", ({0}) ,line);
sb.ToString();

//File.AppendAllText(@"C:/Documents and Settings/Administrator/My Documents/Visual Studio 2008/Projects/ShoppingDataExtractor/spider.txt", match.Value + Environment.NewLine);
}

// Close the response to free resources.
}
myResponse.Close();
resStream.Close();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}

}
}
}

AnswerRe: Help needed with simple Web Spider Code Pin
N a v a n e e t h25-Aug-09 16:41
N a v a n e e t h25-Aug-09 16:41 
QuestionimageList images appear to be getting "corrupted" Pin
shultas25-Aug-09 14:54
shultas25-Aug-09 14:54 
AnswerRe: imageList images appear to be getting "corrupted" Pin
Henry Minute25-Aug-09 22:05
Henry Minute25-Aug-09 22:05 
QuestionRefactoring question Pin
Illegal Operation25-Aug-09 14:42
Illegal Operation25-Aug-09 14:42 
AnswerRe: Refactoring question Pin
Not Active25-Aug-09 15:03
mentorNot Active25-Aug-09 15:03 
AnswerRe: Refactoring question Pin
N a v a n e e t h25-Aug-09 16:26
N a v a n e e t h25-Aug-09 16:26 
QuestionConvert Process to the orginal C# COM class Pin
Gindi Bar Yahav25-Aug-09 13:07
Gindi Bar Yahav25-Aug-09 13:07 
Question[Message Deleted] Pin
WhiteWolf1925-Aug-09 11:49
WhiteWolf1925-Aug-09 11:49 
AnswerRe: C# code help Pin
Not Active25-Aug-09 12:20
mentorNot Active25-Aug-09 12:20 
AnswerRe: C# code help Pin
_Maxxx_25-Aug-09 19:38
professional_Maxxx_25-Aug-09 19:38 
QuestionEnumerator Pin
CodingYoshi25-Aug-09 11:06
CodingYoshi25-Aug-09 11:06 
AnswerRe: Enumerator Pin
Adam R Harris25-Aug-09 11:51
Adam R Harris25-Aug-09 11:51 
GeneralRe: Enumerator Pin
CodingYoshi25-Aug-09 17:20
CodingYoshi25-Aug-09 17:20 
AnswerRe: Enumerator Pin
DaveyM6925-Aug-09 11:51
professionalDaveyM6925-Aug-09 11:51 
AnswerRe: Enumerator Pin
Alan N25-Aug-09 13:45
Alan N25-Aug-09 13:45 
AnswerRe: Enumerator Pin
N a v a n e e t h25-Aug-09 16:36
N a v a n e e t h25-Aug-09 16:36 
GeneralRe: Enumerator Pin
CodingYoshi25-Aug-09 17:22
CodingYoshi25-Aug-09 17:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.