This is a discussion on Reading website content vb.net within the VB.NET Programming forums, part of the Software Development category; Reading website content vb.net Hi, I want the content(text) of the following site in a string so I ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Reading website content vb.net Hi, I want the content(text) of the following site in a string so I can then use ''string.indexof(name) > 0'' to see if names are on the website. I have tried many ways to get this text in a string but all gave me unknown characters which I cannot work with. I know the website is encoded in ISO-8859-1 (windows-1252)... I tried webclient(), stringbuilder(), httpwebrequest() but now I'm out of ideas. http://img231.imageshack.us/img231/6962/59238991.jpg and http://img206.imageshack.us/img206/9538/45143978.jpg I used the following code on a UTF-8 encoded site but this doesnt work on the ISO-8859-1 (windows-1252) site... ![]() Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://www.google.com" ) Dim response As System.Net.HttpWebResponse = request4.GetResponse() Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream( )) String = sr.ReadToEnd() I hope somebody knows a method to get this website's text in a string, thanks
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#2
| |||
| |||
| Hi, See if you have better luck using the System.Net.WebClient object and its DownloadString method. That will put the contents directly in a string so you will not have to worry about encodings, streams, and readers.
__________________ A.Rajesh Khanna |
|
#3
| |||
| |||
| Hi, See if you have better luck using the System.Net.WebClient object and its DownloadString method. That will put the contents directly in a string so you will not have to worry about encodings, streams, and readers. Public Shared Sub DownloadString(ByVal address As String ) Dim client As WebClient = New WebClient() Dim reply As String = client.DownloadString(address) MsgBox(reply) End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Call DownloadString("http://www.google.com" ) End Sub Like this? This still gives same three unreadable characters in the messagebox What am I doing wrong ?
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#4
| |||
| |||
| Hi, Basically, we discuss Code Analysis and Code Metrics issues in our forum, hence, Windows Forms Forum might be your better choice. Based on my understanding, you want to get the content of the specific URL and want it displayed in a MessageBox, right? Would you please try the code snippet below and see if it is want you want? (Instead a message box, I used a RichTextBox control.) string url = "http://www.google.com"; string html = String.Empty; HttpWebRequest request = null; HttpWebResponse response = null; StreamReader sr = null; try { //to establish the request request = (HttpWebRequest)WebRequest.Create(url); //to set the properties request.Timeout = 10000; request.UserAgent = " a simple sample web client"; //retrieve information headers response = (HttpWebResponse)request.GetResponse(); Encoding enc = Encoding.GetEncoding(1252); //Windows default code page sr = new StreamReader(response.GetResponseStream(), enc); html = sr.ReadToEnd(); } catch { throw; } this.richTextBox1.Text = html; response.Close(); sr.Close(); Please have a try and tell me the result! |
|
#5
| |||
| |||
| Hi, Dim bGetAsAsync As Boolean Dim onlinelist As String Label5.Text = "Online: " oHTTP = CreateObject("Microsoft.XMLHTTP") bGetAsAsync = False oHTTP.open("GET", "http://www.google.com", bGetAsAsync) oHTTP.send() onlinelist = oHTTP.responseText For counter = 0 To (ListBox5.Items.Count - 1) If onlinelist.IndexOf(ListBox5.Items.Item(counter)) > 1 Then Label5.Text = Label5.Text + ListBox5.Items.Item(counter) + ", " Next Got it to work. It's much easier to read the website's sourcecode which is not encoded. Thanks for helping
__________________ Shaalini.S ![]() Be the Best of Whatever you are... |
|
#6
| |||
| |||
| Hi friends thanks for share your very important web development view's I have a site for web development that is webdesigningcompany.net This is really a best site for any kind of .NET and other web development languages. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading XML from Javascript | SaravananJ | HTML, CSS and Javascript Coding Techniques | 8 | 08-27-2007 11:09 PM |
| reading data from a file using C# | oxygen | C# Programming | 2 | 08-23-2007 12:48 AM |
| In Microsoft Surface Website. Why they have used Adobe Flash in their website instead | theone | Microsoft | 1 | 07-27-2007 05:12 AM |
| Reading WMV file meta data in .Net | oxygen | C# Programming | 0 | 07-15-2007 10:18 PM |
| What are you reading? | trick-r-treat | The Lounge | 4 | 03-25-2007 06:59 AM |
Our Partners |