简体   繁体   中英

How to scrape data from following html using querySelector or jQuery

I want to get text from this html using querySelector or jQuery.

<td>
   <a href="#" class="verify-address pull-right">
   Verify Address
   </a>
   <div class="verify-address-address-content">
      Tom Heilig<br>
      8642 PEPPER LN<br>
   </div>
   MECHANICSVILLE, VA 22221-4943 US
   <br>
   +1 412-111-1111<br>
   <div class="text-success" style="white-space:normal">
  <span>Address Verified</span>
   </div>
</td>

OUTPUT should be like

Tom Heilig

8642 PEPPER LN

MECHANICSVILLE, VA 22221-4943 US

+1 412-111-1111

Can any one please help me out in this?

Let's say td 's inner content is wrapped inside a div with id datarow like that:

<td>
   <div id="datarow">
      ...
   </div>
</td>

Then this Jquery code will work like charm:

alert(
    $("#datarow").clone()                // Clone the content
                 .find('span').remove()  // Remove all span tags
                 .end()                  // Return to the clone
                 .text()                 // Only text
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM