代码之家  ›  专栏  ›  技术社区  ›  TruMan1

提取区域并将其替换回模板

  •  1
  • TruMan1  · 技术社区  · 15 年前

    我不需要逻辑来合并字段,但我需要提取区域,以便使用逻辑并将其放回模板中。

    <table width="700" border="0" align="center" cellpadding="4" cellspacing="0">
     <tr>
      <td align="center" valign="top">
       <!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_57436_10001"-->
       <table>
        <tbody>
         <tr>
          <td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
         </tr>
         <tr>
          <td><span>[element='h1']</span></td>
         </tr>
         <tr>
          <td><span><strong>[element='price']<br />
          </strong></span><span>[element='was_price']</span></td>
         </tr>
         <tr>
          <td><span><a title="[element='title']" href="[url]">Details</a></span></td>
         </tr>
        </tbody>
       </table>
       <!--DynamicSlotFinish-->
      </td>
      <td align="center" valign="top">
       <!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_3379_10001"-->
       <table>
        <tbody>
         <tr>
          <td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
         </tr>
         <tr>
          <td><span>[element='h1']</span></td>
         </tr>
         <tr>
          <td><span><strong>[element='price']<br />
          </strong></span><span>[element='was_price']</span></td>
         </tr>
         <tr>
          <td><span><a title="[element='title']" href="[url]">Details</a></span></td>
         </tr>
        </tbody>
       </table>
       <!--DynamicSlotFinish-->
      </td>
      <td align="center" valign="top">
       <!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_104854_10001"-->
       <table>
        <tbody>
         <tr>
          <td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
         </tr>
         <tr>
          <td><span>[element='h1']</span></td>
         </tr>
         <tr>
          <td><span><strong>[element='price']<br />
          </strong></span><span>[element='was_price']</span></td>
         </tr>
         <tr>
          <td><span><a title="[element='title']" href="[url]">Details</a></span></td>
         </tr>
        </tbody>
       </table>
       <!--DynamicSlotFinish-->
      </td>
      <td align="center" valign="top">
       <!--DynamicSlotStart url="http://www.test.com/itemdisplay0_10751_-1_80977_10001"-->
       <table>
        <tbody>
         <tr>
          <td><p><a title="[element='title']" href="[url]"><img border="0" alt="[element='title']" src="[element='photo' property='src' maxwidth='135']" width="135" height="135" /></a></p></td>
         </tr>
         <tr>
          <td><span>[element='h1']</span></td>
         </tr>
         <tr>
          <td><span><strong>[element='price']<br />
          </strong></span><span>[element='was_price']</span></td>
         </tr>
         <tr>
          <td><span><a title="[element='title']" href="[url]">Details</a></span></td>
         </tr>
        </tbody>
       </table>
       <!--DynamicSlotFinish-->
      </td>
     </tr>
    </table>
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Nick Martyshchenko    15 年前

    也许这个项目会有帮助: Html Agility Pack

    这是一个敏捷的HTML解析器,它构建了一个读/写DOM并支持纯XPATH或XSLT(实际上您不必理解XPATH或XSLT就可以使用它,不用担心……)。它是一个.NET代码库,允许您解析“OutoftheWeb”HTML文件。解析器对“真实世界”格式错误的HTML非常宽容。对象模型与提议的System.Xml非常相似,只是用于HTML文档(或流)。

    Html Agility包现在支持Linq to对象(通过类似于Linq to Xml的接口)。查看新的测试版以使用此功能

    示例应用程序:

    • 页面修复或生成。你可以 DOM,添加节点,复制节点,

    • 网络扫描仪。 您可以轻松到达img/src或

    • 刮网器。你很容易就废了 将任何现有网页放入RSS 用作绑定的文件。一个 提供了这方面的示例。