How to extract strings from webpage using Regex
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
4 posts
Page 1 of 1
In this tutorial I will show you how to extract text out of webpage sources in order to use them in your program..
For example: http://www.bbc.co.uk/radio1/chart/singles
We want to extract the top 40 singles from this online chart.
First we will put the source code of the page in a string:
Now that we have the source code of the page in a string.. we just need to use regex/getbetween/split to extract the strings we want to get..
Ctrl+U on the site in your browser and find where the text you want to get is, that will be your Regex..
I just use .* as a wildcard which could be anything and put (.+)? where ever the text will be that I need to get, which will be M.Groups(1).Value
Regards,
Skillful
For example: http://www.bbc.co.uk/radio1/chart/singles
We want to extract the top 40 singles from this online chart.
First we will put the source code of the page in a string:
Code: Select all
Note that some websites may return an error and realize that you are not an actual visitor, in that case we will need a webrequest..Dim Source as String = New System.Net.WebClient().DownloadString("http://www.bbc.co.uk/radio1/chart/singles")
Now that we have the source code of the page in a string.. we just need to use regex/getbetween/split to extract the strings we want to get..
Ctrl+U on the site in your browser and find where the text you want to get is, that will be your Regex..
Code: Select all
Dim Regex As String = " <img src=""/radio1/images/auto/70x70/.*"" alt=""(.+)?"" class=""cover"" height=""70"" width=""70"" />"
I just use .* as a wildcard which could be anything and put (.+)? where ever the text will be that I need to get, which will be M.Groups(1).Value
Code: Select all
Theres your loop and there you have it. For Each M As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(Source, Regex)
MessageBox.Show(M.Groups(1).Value)
Next
Regards,
Skillful
Instead of LOL use this -
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
You might want to tell more about Regular Expressions, since this does only work on one webpage and people to don't know how to use regex won't be able to use this to get other information.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Yeah this is true.
Just wrote this while on my dad's laptop.
Will update it later
Just wrote this while on my dad's laptop.
Will update it later
Instead of LOL use this -
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
LSIBMHBIWFETALOL
Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
how can i do the same thing but have it posted to a label instead of a messagebox
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023