如何抓取没有 class 使用 javascript
How to scraping there are not class using javascript
如何在没有任何数据时废弃数据class 我知道使用 ID,Class 使用 document.getElementsByClassName
。
<tr id="overview-summary-current">
<th scope="row">
<span class="edit-tools">
<a href="#background-experience" class="edit-section" id="control_gen_5">Edit experience
</a>
</span>
<a href="#background-experience" data-trk="prof-0-ovw-curr_pos">Current</a>
</th>
<td>
<ol>
<li>
<strong>
<a href="/company/10097785?trk=prof-0-ovw-curr_pos" dir="auto">SNT Solutions rajkot</a>
</strong>
</li>
</ol>
</td>
</tr>
我想 SNT Solutions rajkot
如何使用 JavaScript 在变量中获取该值。
trk=prof-0-ovw-curr_pos
在网页中是唯一的
简单方法(纯js):
var linksWithoutClass = document.querySelectorAll('#overview-summary-current a'); // return nodeList iterrator
var linksArray = [].slice.call(linksWithoutClass); // create array from Nodelist
linksArray.filter( function(link){ // filter list to get <a> without any class
return link.classList.length === 0;
});
我有一个简单的解决方案
var a1 = document.querySelector('a[href$="trk=prof-0-ovw-curr_pos"]').text;
console.log('Data is :::::'+a1);
如何在没有任何数据时废弃数据class 我知道使用 ID,Class 使用 document.getElementsByClassName
。
<tr id="overview-summary-current">
<th scope="row">
<span class="edit-tools">
<a href="#background-experience" class="edit-section" id="control_gen_5">Edit experience
</a>
</span>
<a href="#background-experience" data-trk="prof-0-ovw-curr_pos">Current</a>
</th>
<td>
<ol>
<li>
<strong>
<a href="/company/10097785?trk=prof-0-ovw-curr_pos" dir="auto">SNT Solutions rajkot</a>
</strong>
</li>
</ol>
</td>
</tr>
我想 SNT Solutions rajkot
如何使用 JavaScript 在变量中获取该值。
trk=prof-0-ovw-curr_pos
在网页中是唯一的
简单方法(纯js):
var linksWithoutClass = document.querySelectorAll('#overview-summary-current a'); // return nodeList iterrator
var linksArray = [].slice.call(linksWithoutClass); // create array from Nodelist
linksArray.filter( function(link){ // filter list to get <a> without any class
return link.classList.length === 0;
});
我有一个简单的解决方案
var a1 = document.querySelector('a[href$="trk=prof-0-ovw-curr_pos"]').text;
console.log('Data is :::::'+a1);