Click here to Skip to main content
15,889,216 members
Home / Discussions / C#
   

C#

 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Night Lol19-Jul-10 5:51
Night Lol19-Jul-10 5:51 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
DaveyM6919-Jul-10 7:46
professionalDaveyM6919-Jul-10 7:46 
AnswerRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Luc Pattyn19-Jul-10 5:33
sitebuilderLuc Pattyn19-Jul-10 5:33 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Night Lol19-Jul-10 5:52
Night Lol19-Jul-10 5:52 
QuestionUnable to reference shared assembly in GAC [modified] Solved Pin
Jonathan Davies19-Jul-10 2:30
Jonathan Davies19-Jul-10 2:30 
AnswerRe: Unable to reference shared assembly in GAC Pin
PIEBALDconsult19-Jul-10 3:13
mvePIEBALDconsult19-Jul-10 3:13 
GeneralRe: Unable to reference shared assembly in GAC Pin
Jonathan Davies19-Jul-10 4:02
Jonathan Davies19-Jul-10 4:02 
QuestionHTML Table tag text Scraping Pin
NaveenHS19-Jul-10 0:48
NaveenHS19-Jul-10 0:48 
Hello Everyone,

I have one simple static HTML file, with a table i am trying to extract the contents of the table to a file.

can anyone please give some some suggestions how to proceed with this work.

HTML File:-

<html>
<body>

<table border="1">
<tr>
<th>Team Name</th>
<th>Place</th>
</tr>
<tr>
<td>Kings XI Punjab</td>
<td>Punjab</td>
</tr>
<tr>
<td>Chennai Super Kings</td>
<td>Chennai</td>
</tr>

<tr>
<td>Deccan Chargers</td>
<td>Hydrabad</td>
</tr>

</table>


</body>
</html>


I am trying to extract the text with this code :-

using System.Diagnostics;
using System.Net;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System;
using System.IO;
using System.Linq;

class Program
{
	static void Main()
	{
		StreamReader str = new StreamReader("C:\\Sample1.html");
		string strLings = str.ReadToEnd();
		int startIndex = strLings.IndexOf("<table>");
		int endInedx = strLings.IndexOf("</table>") + "</table>".Length - startIndex;
		string strTab = strLings.Substring(startIndex, endInedx);
		str.Close();
		StreamWriter strWr = new StreamWriter("C:\\test2.txt", true);
		strWr.Write(strTab);
		strWr.Close();
	}
}



Problem is i am getting an error

An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

Additional information: StartIndex cannot be less than zero.
AnswerRe: HTML Table tag text Scraping Pin
Luc Pattyn19-Jul-10 0:57
sitebuilderLuc Pattyn19-Jul-10 0:57 
GeneralRe: HTML Table tag text Scraping Pin
NaveenHS19-Jul-10 1:45
NaveenHS19-Jul-10 1:45 
GeneralRe: HTML Table tag text Scraping Pin
Not Active19-Jul-10 5:41
mentorNot Active19-Jul-10 5:41 
AnswerRe: HTML Table tag text Scraping Pin
ragnaroknrol19-Jul-10 4:04
ragnaroknrol19-Jul-10 4:04 
GeneralRe: HTML Table tag text Scraping Pin
Luc Pattyn19-Jul-10 4:29
sitebuilderLuc Pattyn19-Jul-10 4:29 
AnswerRe: HTML Table tag text Scraping Pin
PIEBALDconsult19-Jul-10 4:21
mvePIEBALDconsult19-Jul-10 4:21 
QuestionReading user/group of your local machine Pin
dabuskol19-Jul-10 0:39
dabuskol19-Jul-10 0:39 
QuestionHi Pin
KORCARI18-Jul-10 23:27
KORCARI18-Jul-10 23:27 
AnswerRe: Hi Pin
Mycroft Holmes19-Jul-10 2:57
professionalMycroft Holmes19-Jul-10 2:57 
GeneralRe: Hi Pin
KORCARI19-Jul-10 3:19
KORCARI19-Jul-10 3:19 
QuestionSending XML over a Socket connection Pin
Priya Prk18-Jul-10 22:53
Priya Prk18-Jul-10 22:53 
AnswerRe: Sending XML over a Socket connection Pin
Peace ON18-Jul-10 23:08
Peace ON18-Jul-10 23:08 
QuestionRead both attributes and subtree of an XML element using XmlTextReader Pin
PPKeno18-Jul-10 22:05
PPKeno18-Jul-10 22:05 
AnswerRe: Read both attributes and subtree of an XML element using XmlTextReader Pin
Peace ON18-Jul-10 22:34
Peace ON18-Jul-10 22:34 
QuestionReading .dbc file in C# Pin
Niungareamit18-Jul-10 20:14
Niungareamit18-Jul-10 20:14 
AnswerRe: Reading .dbc file in C# Pin
V.18-Jul-10 20:32
professionalV.18-Jul-10 20:32 
AnswerRe: Reading .dbc file in C# Pin
Richard MacCutchan18-Jul-10 22:33
mveRichard MacCutchan18-Jul-10 22:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.