Regex and extract information from webpage (scraping)

I am trying to scrape the ISIN Number from yahoo finance pages and need some help.

I have built the url that I need but can not figure out how to scrape this information. I have attached a text file (which essentially is the web page) and here is the link to the page.
LVL 17
Who is Participating?

Improve company productivity with a Business Account.Sign Up

smash_pantsConnect With a Mentor Commented:
Here it is in

Dim result As String = Nothing
Dim url As String = ""
Dim response As WebResponse = Nothing
Dim reader As StreamReader = Nothing

	Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
	request.Method = "GET"
	response = request.GetResponse()
	reader = New StreamReader(response.GetResponseStream(), Encoding.UTF8)
	result = reader.ReadToEnd()
Catch ex As Exception
	' handle error
	If reader IsNot Nothing Then
	End If
	If response IsNot Nothing Then
	End If
End Try
For Each txt As Match In Regex.Matches(result, "^.*ISIN (.{12}) \).*$", RegexOptions.Multiline)

Open in new window

download the html page, then
use something like ReadAllText function to read the html page's source, then
use a InStr function to find "ISIN" - the value your after is just infront of this location in the text string,
and is ended by a closing paretheses - which you may easily find too

hope this makes sense to you, quite some work is yet to be done...good luck
you could use xpath to access the text for the ISIN:


If you really need a regex for it then here you go:
^.*ISIN (.{12}) \).*$
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

nepaluzAuthor Commented:
ErezMor thanks for the contrib. I will give it a bash andsee what I come up with.

smash_pants (what a name!)I really am interested in the regex but can not get it to work. Heres the code I am using (and don't laugh!)

Dim fxk = Regex.Matches(sr.ReadToEnd.ToString, "^.*ISIN (.{12}) \).*$")

Open in new window

nepaluzAuthor Commented:
OK - I have been un-able to implement either way suggested here, and though they may be correct, I am un-able to award poits for them. I am thus closing this thread and will try another one.
since the last post from user was "i'll give it a try and get back to you...", i dont think his closing reason is justified.
i happen to have some actual experience in doing just what i suggested the user, so in terms of if it works or not, there's no doubt here.
unless i didnt understand his question, or his closing request reason...

nepaluzAuthor Commented:
OK then erez, I have been unable to use the instr as suggested (I think I have to repeat the obvious), could you post some code to this end?
I've tested this code and it works.
Sorry i haven't been around much... I'm moving house.

string result = null;
string url = "";
WebResponse response = null;
StreamReader reader = null;

try {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.Method = "GET";
    response = request.GetResponse();
    reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
    result = reader.ReadToEnd();
catch (Exception ex) {
    // handle error
finally {
    if (reader != null)
    if (response != null)
foreach (Match txt in Regex.Matches(result, @"^.*ISIN (.{12}) \).*$", RegexOptions.Multiline)) {

Open in new window

nepaluzAuthor Commented:
Thanks a lot and happy moving! If I may ask for a tweak, is it possible to have the regex NOT limiting the result string to 12 characters as you have it, but pich up to the closing bracket?

The ISIN (could?) be longer than 12 characters long and it would thus return an incomplete numer (or I am wrong?)

I have awarded the marks anyhow.
in the regex:
^.*ISIN (.{12}) \).*$

just change the .{12} to what you need.

Capital letters an numbers at least 12 chars long:

any character ,any length:

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.