IT Community - Software Programming, Web Development and Technical Support

Reading website content vb.net

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > VB.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 06-18-2009, 08:32 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Reading website content vb.net

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 06-18-2009, 08:32 PM
arjkhanna arjkhanna is offline
D-Web Incredible
 
Join Date: Mar 2007
Posts: 1,949
arjkhanna is on a distinguished road
Default Re: Reading website content vb.net

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 06-18-2009, 09:05 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: Reading website content vb.net

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 06-18-2009, 10:19 PM
bluesky bluesky is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 667
bluesky is on a distinguished road
Default Re: Reading website content vb.net

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!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 06-18-2009, 10:22 PM
shaalini shaalini is offline
D-Web Architect
 
Join Date: Apr 2007
Posts: 633
shaalini is on a distinguished road
Default Re: Reading website content vb.net

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...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 10-02-2009, 12:57 AM
garuav123456 garuav123456 is offline
Banned
 
Join Date: Sep 2009
Posts: 31
garuav123456 is on a distinguished road
Default Re: Reading website content vb.net

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.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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


All times are GMT -7. The time now is 06:33 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0