HttpWebResponse resp = (HttpWebResponse)req.GetResponse();//Convert
the data into a string (assumes that you are requesting text)
StreamReader sr =
new
StreamReader(resp.GetResponseStream());string readcontents
= "";for (int
i = 0; i <= 58; i++)//while (!(readcontents == null)) <TD|<TR|</TD>|<TD|</TR>
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Just go the article no need to write Regular Expression.
You only need to make sure replace runat ="server" with the control that you need in Page.
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Edwin_Pro_Ne...
Member
12 Points
60 Posts
Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 28, 2009 06:52 AM|LINK
Anyone can help me ?
Get viewsource data from HTML and yet set regular expression to ignore the unnecessary <TD></TD>, other html element as well. only need the text data.
{
private void autorun()//Create the HttpWebRequest object{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.nowgoal.com/OddsComp.aspx?id=318122");try{
//Get the data as an HttpWebResponse object
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();//Convert the data into a string (assumes that you are requesting text)
StreamReader sr = new StreamReader(resp.GetResponseStream());string readcontents = "";for (int i = 0; i <= 58; i++)//while (!(readcontents == null)) <TD|<TR|</TD>|<TD|</TR>{
Regex regex = new Regex("<TD[^>]*>([^<])+</TD>");string[] raw_data = regex.Split(readcontents);//string[] raw_data = readcontents.Split('<');
//for (int x=0; x<raw_data.Length; x++)
//{
//}{
txtOutput.Text = txtOutput.Text + raw_data[k].ToString();
}
}
for (int k = 0; k < raw_data.Length; k++)// string results = sr.ReadToEnd();sr.Close();
// html.Text = results;
}
{
Response.Write(
}
}
}
catch (WebException wex)"<font color=red>SOMETHING WENT AWRY!<br />Status: " + wex.Status + "Message: " + wex.Message + "</font>");{
readcontents = sr.ReadLine();
}
html.Text = readcontents;
thuhue
All-Star
15625 Points
3146 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 28, 2009 02:32 PM|LINK
What is the source of the html data in question?
Edwin_Pro_Ne...
Member
12 Points
60 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 29, 2009 02:31 AM|LINK
PeteNet
All-Star
81342 Points
11398 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 29, 2009 02:50 AM|LINK
you can strip all the html tags with this expression: <(.|\n)*?>
refer here for additional info: http://weblogs.asp.net/rosherove/archive/2003/05/13/6963.aspx
you could also consider using the HtmlAgilityPack which will go through the elements and you'd be able to query it like with xml. http://htmlagilitypack.codeplex.com/Thread/View.aspx?ThreadId=67224 - that's the support where you can see a similar example
I think, however, the first option should work for you.
strip html tags text within html tags
Peter
Edwin_Pro_Ne...
Member
12 Points
60 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 29, 2009 03:01 AM|LINK
thx Pete, u such a genius.........
by the way, how to write the regular expression, mind to share with me ? coz it seem like complicated for me...
anyway , thanx a lot
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 29, 2009 05:45 AM|LINK
if you want to do this like, Page.FindControl
http://www.highoncoding.com/Articles/605_Creating_Dynamic_Page_from_Any_URL.aspx
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Edwin_Pro_Ne...
Member
12 Points
60 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 29, 2009 06:16 AM|LINK
how about ignore character and just need the numerical value only..........
I'm poor in regular expression writing...........
thx
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 29, 2009 06:35 AM|LINK
Just go the article no need to write Regular Expression.
You only need to make sure replace runat ="server" with the control that you need in Page.
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Edwin_Pro_Ne...
Member
12 Points
60 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Oct 31, 2009 03:44 AM|LINK
To imran_ku07
Sorry, I dont really understand what you mean in that article.
1. These classes need to put in the single aspx.cs file ?
public class MyProvider : System.Web.Hosting.VirtualPathProvider
public class MyVirtualFile : System.Web.Hosting.VirtualFile
2. What mean by code statement below ? file provide ?
System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(fileProvide)
3. What's need to clear and where should i put the statement below ?
((HtmlInputText)myPage.FindControl("TextBox1")).Value
4. Can you include the namespace as well ?
(for eg using System.Web.Compilation etc ?)
5. Could you please show sample demo(asp.net C#) which available to download ?
Thank You Imran.......
regard
Edwin
Edwin_Pro_Ne...
Member
12 Points
60 Posts
Re: Get viewsource data from HTML and yet set regular expression to ignore <TD></TD>
Nov 01, 2009 02:37 AM|LINK
Imran_ku07
u such a..
wanna give some tips to people but not completed....
ask question didn't reply...
sigh..... go to ur site post question also didn't answer......