hi
suche hilfe um eine webanwendung zum parsen von internet seiten und deren auswertung.(wenn moeglich die daten in einer datenbank abspeichern)
alleine komme ich nicht ganz zurecht damit.
es ist fuer eine facharbeit zu aufstellung einer statistik.
ihr macht das natuerlich nicht umsonst.
bei intresse mailen neral@gmx.net
Eigentlich solle das mit System.XML möglich sein....
--
mfg
Franknstein
Besuchen sie das VisualC++ - Forum
Hi,
also ich habe nun folgendes:
[PHP]
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
//Zum Auslesen der Seite
using System.Net;
using System.IO;
using System.Text;
namespace WebApplication4
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Label Label2;
private void Page_Load(object sender, System.EventArgs e)
{
string texturl = TextBox1.Text;
}
#region Vom Web Form-Designer generierter Code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: Dieser Aufruf ist für den ASP.NET Web Form-Designer erforderlich.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = TextBox1.Text;
Label3.Text = auslesen();
}
public string auslesen()
{
string htmlcode = null;
Uri url = new Uri(TextBox1.Text);
//Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
//Console.WriteLine("\r\nResponse stream received.");
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
//Console.WriteLine("HTML...\r\n");
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String(read, 0, count);
htmlcode = htmlcode + str;
count = readStream.Read(read, 0, 256);
}
// Console.WriteLine("");
// Console.ReadLine();
// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close();
return htmlcode;
}
}
}
[/PHP]
Soweitso gut ich habe die Methode auslesen etwas geaendert, so dass sie einen string als Rueckgabewert hat(htmlcode) und dort auch der gesamte Quellcode gespeichert wird.
hier die orgianl Methode:
[PHP]
using System;
using System.Net;
using System.IO;
using System.Text;
namespace ConsoleApplication5
{
class Class1
{
static void Main(string[] args)
{
Uri url = new Uri("http://www.google.de");
//Creates an HttpWebRequest with the specified URL.
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
// Sends the HttpWebRequest and waits for the response.
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
// Gets the stream associated with the response.
Stream receiveStream = myHttpWebResponse.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader( receiveStream, encode );
Console.WriteLine("\r\nResponse stream received.");
Char[] read = new Char[256];
// Reads 256 characters at a time.
int count = readStream.Read( read, 0, 256 );
Console.WriteLine("HTML...\r\n");
while (count > 0)
{
// Dumps the 256 characters on a string and displays the string to the console.
String str = new String(read, 0, count);
Console.Write(str);
count = readStream.Read(read, 0, 256);
}
Console.WriteLine("");
// Releases the resources of the response.
myHttpWebResponse.Close();
// Releases the resources of the Stream.
readStream.Close();
}
}
}
[/PHP]
Fehler werden zwar nicht angezeigt, nur irgendwas stimmt damit nicht:
[PHP]
private void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = TextBox1.Text;
Label3.Text = auslesen();
}
[/PHP]
also wenn ich jetzt sagen wir http://www.google.de eingebe, kommt ein schwarzes Bild und beim Label3 wo eigentlich der Quelltext ausgegeben werden soll sonen kleines rotes Kreuz oben links.
ich hoffe mir kann jemand helfen.
gruss neral