quelltext auslesen und im string speichern

Neral

Mitglied
hi ich wuerde gerne von einer seite sagen wir mal google.de den quelltext in einem string speichern um dann spaeter den auszuwerten ich habe es mit system.xml versucht da bekomme ich aber leider nur die tags raus:

hier der code:

Code:
XmlTextReader reader = new XmlTextReader("http://www.google.de/");

			while(reader.Read())
			{
				switch(reader.NodeType)
				{
					case XmlNodeType.Element:
						Debug.WriteLine(string.Format("{0}", reader.Name));
						break;
				}
				
			}
			reader.Close();

also bin fuer jeden code schnipsel dankbar und auch fuer aehnliche beispiele oder sowas.

gruss neral
 
Geht das nicht auch mit den HttpWebRequest / HttpWebResponse Klassen? Mit der GetResponse() Methode hättest du dann doch den Stream der vom Server zurückkommt...den kannst dann ja auswerten oder wegschreiben oder so.
Oder hab ich da was falsch verstanden? :rolleyes:
 
urg jo stimmt danke thx hast mir echt weiter geholfen :)
aber irgendwie geht das nicht ganz koenntet ihr mal rueber schauen

PHP:
using System;
using System.Net;


namespace ConsoleApplication5
{
	class Class1
	{
		static void Main(string[] args)
		{
			string url = "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();


			/*HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
			HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
			// Insert code that uses the response object.
			HttpWResp.Close();*/
		}
	}
}

habe ich die falschen klassen eingebunden ?

oder was habe ich falsch gemacht ?!

gruss und thx nochmal.
 
Hallo.

Neral, bitte lies unsere Netiquette, beziehungsweise den roten Kasten unter dem Eingabefeld für Beiträge.

Bitte achte unbedingt auf Deine Rechtschreibung, eine klare Fragestellung bzw. Antwort und eine sinnvolle Struktur. Beiträge mit durchgehender Kleinschreibung, Chatsprache und/oder mangelhafter Struktur werden kommentarlos gelöscht.
Mehr dazu findest Du in unserer Netiquette.

Wenn du bei einem Code einen Fehler hast, zeig und auch bitte die Fehlermeldung, aber in deinem Fall, versuches es mal mit einem
Code:
using System.IO;
System.Text;
bei den anderen Using-Anweisungen.

MfG,
Alex
 
Uii tut mir leid, diese roten Sachen habe ich nicht ganz gelesen :).

Also, ich habe das nun hinzugefuegt und jetzt kommt folgendes:

--------------------------------------------------------------------------------------------------------
C:\Dokumente und Einstellungen\Szymon\Eigene Dateien\Visual Studio Projects\ConsoleApplication1\Class1.cs(11):
Die beste Übereinstimmung für die überladene Methode 'string.String(char*)' hat einige ungültige Argumente

C:\Dokumente und Einstellungen\Szymon\Eigene Dateien\Visual Studio Projects\ConsoleApplication1\Class1.cs(11):
Argument '1': kann nicht von 'string' zu 'char*' konvertiert werden

C:\Dokumente und Einstellungen\Szymon\Eigene Dateien\Visual Studio Projects\ConsoleApplication1\Class1.cs(13):
Der Typ oder Namespace 'Response' konnte nicht gefunden werden. Möglicherweise fehlt eine Anweisung oder ein Assemblyverweis.
--------------------------------------------------------------------------------------------------------

Hier nochmal der Code:

PHP:
using System;
using System.Net;
using System.IO;
using System.Text;

namespace ConsoleApplication5
{
	class Class1
	{
		static void Main(string[] args)
		{
			string url = "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();


			/*HttpWebRequest HttpWReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com");
			HttpWebResponse HttpWResp = (HttpWebResponse)HttpWReq.GetResponse();
			// Insert code that uses the response object.
			HttpWResp.Close();*/
		}
	}
}
 
Ich hab mir mal den code kopiert und bei mir gehts!
Das Einzige was ich geändert habe ist eigentlich, dass ich URL als Uri deklariert habe:
Code:
Uri URL = new Uri("www.google.de");

Hab mich extra angemolden um das zu posten, hoffe es hilft dir!
 
Hi SUPER! :)
Es geht nun. Aber nur zum Verstaendniss was ist Uri fuer eine Klasse ?!

hm.. wenn Ihr das ausfuehrt kommt bei Euch was in der Konsole als Ausgabe?,bei mir irgendwie nicht :\

Hier nochmal der Code, der sich ausfuehren laesst:

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(); 
		} 
	} 
}

gruss
 
Zurück