html
  • class
  • extract
  • 2015-05-19 108 views -3 likes 
    -3

    我有html页面的源代码,我想要做的是从中提取选择性信息。例如,在源代码这样的:从html页面提取类内容

    <div class="date"> 
    <strong>Date:</strong> 03/04/2015 </div> 
    

    ,我想提取的是“日期:2015年3月4日”

    或本:

    <div class="name"> 
        <strong>Name:</strong> <a href = 'http://www.example.com' title='Title'>Jhon Smit</a > 
    

    和我想要提取'Jhon Smit' ,这个操作对于网页中的很多东西。有没有快速的方法来做到这一点?

    回答

    2

    使用textContent元素的属性。

    顺便说一句,DL列表是更适合来标记这类东西:

    <dl class="name"> 
        <dt>Name:</dt> 
        <dd><a href="http://www.example.com">Jhon Smit</a></dd> 
    </dl> 
    
    相关问题