Re: Read text from a website
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)
Re: Read text from a website
Quote:
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?
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.
Re: Read text from a website
Quote:
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?
Re: Read text from a website
vb.net Code:
TextBox1.Text = Regex.Match(html, "(?<=<p class=""welcome-msg"">).+(?=</p>)").Value
Re: Read text from a website
Quote:
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
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
Re: Read text from a website
Quote:
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
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
Re: Read text from a website
Quote:
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.
Re: Read text from a website
Quote:
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?
Re: Read text from a website
Code:
Imports System.Text.RegularExpressions
Imports System.Net
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Html As String
Dim wc As New WebClient
Html = wc.DownloadString("http://localhost/index1.html")
LinkLabel1.Text = Regex.Match(Html, "(?<=<a class=""Url"">).+(?=</a>)").Value
End Sub
End Class
This is Correct solution :check: but
how to read URL ?? :(
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!