|
-
Sep 2nd, 2012, 09:54 AM
#1
Thread Starter
Addicted Member
Read text from a website
Hello,
I'd like someone to give me the code for reading text of a website if thats possible.
For example
I want to read this from a website
<p class="welcome-msg">Welcome, username</p>
So the program will find the welcome-msg class
and will write down
Welcome, Username
-
Sep 2nd, 2012, 11:47 AM
#2
Thread Starter
Addicted Member
Re: Read text from a website
-
Sep 2nd, 2012, 04:08 PM
#3
Re: Read text from a website
Try this.
vb.net Code:
Dim html As String = "<p class=""welcome-msg"">Welcome, username</p>" Debug.Print(Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value)
-
Sep 2nd, 2012, 04:20 PM
#4
Thread Starter
Addicted Member
Re: Read text from a website
 Originally Posted by Chris001
Try this.
vb.net Code:
Dim html As String = "<p class=""welcome-msg"">Welcome, username</p>" Debug.Print(Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value)
What is Regex?
-
Sep 2nd, 2012, 04:25 PM
#5
Re: Read text from a website
I'll give you the same reply I gave somebody else 10 minutes ago.
Hover your mouse cursor over the red underscore, click on the red exclamation mark that appears and click on the 'Import' line.
-
Sep 2nd, 2012, 04:27 PM
#6
Thread Starter
Addicted Member
Re: Read text from a website
 Originally Posted by Chris001
I'll give you the same reply I gave somebody else 10 minutes ago.
Hover your mouse cursor over the red underscore, click on the red exclamation mark that appears and click on the 'Import' line.
And how can i make it so it will appear the welcome message on a textbox?
-
Sep 2nd, 2012, 04:28 PM
#7
Re: Read text from a website
vb.net Code:
TextBox1.Text = Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value
-
Sep 2nd, 2012, 04:31 PM
#8
Thread Starter
Addicted Member
Re: Read text from a website
 Originally Posted by Chris001
vb.net Code:
TextBox1.Text = Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value
For somereason textbox1.text writes Welcome, username. Where username i want to write the username it appears on the website
-
Sep 2nd, 2012, 04:37 PM
#9
Re: Read text from a website
I simply showed you how to extract the text between "<p class="welcome-msg">" and "</p>".
If you want to extract it from a webpage, then you must first download the webpage. You can do that with WebClient DownloadString.
http://msdn.microsoft.com/en-us/library/fhd1f0sw
-
Sep 2nd, 2012, 04:39 PM
#10
Thread Starter
Addicted Member
Re: Read text from a website
 Originally Posted by Chris001
I simply showed you how to extract the text between "<p class="welcome-msg">" and "</p>".
If you want to extract it from a webpage, then you must first download the webpage. You can do that with WebClient DownloadString.
http://msdn.microsoft.com/en-us/library/fhd1f0sw
I am sorry but i never understand msdn.Microsoft.com, i will try though. But if it is possible for you, give me the full code. so i can read it and understand what it is from the source. Thanks
-
Sep 2nd, 2012, 05:06 PM
#11
Re: Read text from a website
I bet you haven't even looked at that link. It's only three lines of code to download a webpage.
vb.net Code:
Imports System.Text.RegularExpressions
Imports System.Net
Dim html As String
Using wc As New WebClient
html = wc.DownloadString("http://website.com")
End Using
TextBox1.Text = Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value
-
Sep 2nd, 2012, 05:22 PM
#12
Thread Starter
Addicted Member
Re: Read text from a website
 Originally Posted by Chris001
I bet you haven't even looked at that link. It's only three lines of code to download a webpage.
vb.net Code:
Imports System.Text.RegularExpressions Imports System.Net Dim html As String Using wc As New WebClient html = wc.DownloadString("http://website.com") End Using TextBox1.Text = Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value
Well you are wrong. I looked at the link. I was realy close! I am proud since it was the first time i almost understand microsofts tutorials. I just didn't added the Imports System.Text.regularExpression . Anyways, thanks. I will try the code
EDIT: Wrong, they automaticly got in, so i don't know why my code didn't worked last time.
-
Sep 3rd, 2012, 02:42 AM
#13
Thread Starter
Addicted Member
Re: Read text from a website
 Originally Posted by Chris001
I bet you haven't even looked at that link. It's only three lines of code to download a webpage.
vb.net Code:
Imports System.Text.RegularExpressions Imports System.Net Dim html As String Using wc As New WebClient html = wc.DownloadString("http://website.com") End Using TextBox1.Text = Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value
Here is another problem, Although the code works perfect, after login, it says Welcome guest, and not welcome name. And i can't findout why it does that. any idea?
-
Sep 3rd, 2012, 06:16 AM
#14
Junior Member
-
Sep 3rd, 2012, 09:23 AM
#15
Thread Starter
Addicted Member
Re: Read text from a website
For some reason my website doesn't get updated really quick.
So as result, i don't get a Welcome, username and i get a welcome, Guest.
But if i see the webbrowser, i can see that it says on the browser welcome, username
and it doesn't say welcome, Guest
Any fixes?
Thanks!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|