How to grab the data displayed in a web page


hi,

i want grab data displayed in web page . data displayed follows .

please note has more 3 rows of data

code     name                             fax
1000     azeem abdhillaahi      3322436
1001     moosa hashim             3318551
1002     magpie                           3123464

    <h2>cutomers</h2>               <table class="thintable" width="100%" border="0" cellpadding="5" cellspacing="0" >              <tr>                  <td width="9%" bgcolor="#e9e9e9" class="tdline">                      <strong>code</strong>                  </td>                  <td bgcolor="#e9e9e9" class="style1">                      name</td>                  <td width="11%" bgcolor="#e9e9e9" class="tdline">                      <strong>fax</strong>                  </td>              </tr>              <tr>                  <td class="tdline">                      1000                  </td>                  <td class="style1">                      azeem abdhillaahi                  </td>                  <td class="tdline">                      3322436                  </td>              </tr>              <tr>                  <td class="tdline">                      1001                  </td>                  <td class="style1">                      moosa hashim                  </td>                  <td class="tdline">                      3318551                  </td>              </tr>              <tr>                  <td class="tdline">                      1002                  </td>                  <td class="style1">                      magpie                  </td>                  <td class="tdline">                      3123464</td>              </tr>          </table>


i want exract data , save text file comma seperated values.

i want achieve taks using asp.net c#. please provide me links sample or tutorial .


thank you

mohamed ziyad

hi,

i able data using following code

        protected void button1_click(object sender, eventargs e)          {              string result = string.empty;              var web = new htmlweb();             const string url = @"http://localhost:5355/default.aspx";                         var request = (httpwebrequest)webrequest.create(url);              request.useragent = "mozilla/4.0 (compatible; msie 7.0; windows nt 6.0)";                request.method = "post";                           request.contenttype = "application/x-www-form-urlencoded";              using (var stream = request.getresponse().getresponsestream())                  if (stream != null)                      using (var reader = new streamreader(stream, encoding.utf8))                      {                          result = reader.readtoend();                      }                var doc = new htmldocument();              doc.load(new stringreader(result));              //  htmldocument doc = web.load(url);                             const string filename = @"c:\users\user\documents\test.txt";              var objwriter = new streamwriter(filename, true);                // tables in document              htmlnodecollection tables = doc.documentnode.selectnodes("//table");              string stringcontent = "";              // iterate rows in first table              htmlnodecollection rows = tables[0].selectnodes(".//tr");              // .skip(1) start second row              foreach (htmlnode t in rows.skip(1))              {                  // iterate columns in row                  htmlnodecollection cols = t.selectnodes(".//td");                  string stringcelltext = "";                  foreach (htmlnode col in cols)                  {                      // value of column , print                      if (string.isnullorempty(stringcelltext))                          stringcelltext = "\"" + col.innertext.replace("\r\n", "").trim() + "\"";                      else                          stringcelltext += "," + "\"" + col.innertext.replace("\r\n", "").trim() + "\"";                  }                  if (string.isnullorempty(stringcontent))                      stringcontent = stringcelltext;                  else                      stringcontent += "\n" + stringcelltext;                  //write data text file                  objwriter.write(stringcontent);              }              objwriter.close();              response.clear();              response.contenttype = "text/plain";              response.addheader("content-disposition", "attachment;filename=download.csv");              response.write(stringcontent);              response.end();            }  

thank you

mohamed ziyad



Silverlight  >  Programming Silverlight with .NET – General



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'