2010-07-21 80 views

回答

0

其實HTML表中的值,典型的動態HTML頁上,該表的值從數據庫加載。但是,如果你願意,你仍然可以解析頁面的源代碼,並將每一行的值保存到數據庫中。那是你想要做的嗎?

+0

告訴我一些語法 – shamim 2010-07-21 12:20:18

1

你可以使用HTML敏捷包像這樣:

WebClient webClient = new WebClient(); 
    const string strUrl = "http://www.myspace.com/centuryman"; 

    // Setup proxy for internal stuff 
    //System.Net.WebProxy pry = new System.Net.WebProxy("194.80.164.8", 80); 
    //pry.Credentials = CredentialCache.DefaultCredentials; 
    //WebRequest.DefaultWebProxy = pry; 

    Stream s = webClient.OpenRead(strUrl); 

    HtmlDocument doc = new HtmlDocument(); 
    doc.Load(s); 

    HtmlNode link = doc.DocumentNode.SelectNodes("//*[@id='profile_bandschedule']")[0]; 

這將返回你enumarable對象,你可以循環並插入HTML的值到數據庫中。

見另一個例子:

How to use HTML Agility pack

+0

使用的HTMLDocument和HtmlNode其命名空間,我需要對我的project.VS 2008年增加給我看消息添加參考 – shamim 2010-07-21 12:56:30

+1

看看我在底部添加的鏈接,那裏有一個更全面的例子。它還包含HTML Agiliy包的下載鏈接。你需要下載。將dll添加到bin directry中,然後在vs項目中引用它。 – Mantisimo 2010-07-21 15:04:50

0

您可以用jQuery解析表,創建客戶端數組或對象,並使用AJAX調用或郵寄的形式發送回服務器。

HTML:

<!DOCTYPE html> 
<html> 
<head> 
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<meta charset=utf-8 /> 
<title>JS Bin</title> 
<!--[if IE]> 
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
</head> 
<body> 
    <table id="tableData"> 
    <tr id="tableHeader"> 
     <td>col1</td> 
     <td>col2</td> 
     </tr>  
     <tr id="tableRow"> 
     <td>data1row1</td> 
     <td>data2row2</td> 
     </tr> 
     <tr id="tableRow">   
     <td>data1row2</td> 
     <td>data2row3</td> 
     </tr> 
    </table> 
</body> 
</html> 

SCRIPT:

$(document).ready(function() { 
    //parse all the data 
    $('#tableData tr').each(function() { 
     if($(this).attr('id')=='tableHeader') 
     { 
      alert('this is the header row');   
     }  
     $('td', this).each(function() {    
       alert($(this).html()); 
     }); 

    }); 

    //post the form or send data via AJAX 

});