1-我写了什么代码来获取此代码中的所有"想要访问"元素,没有其他元素,例如"某些数据",并且只想要在div类bestMFdtl2中具有的元素。
2-如果我想要根据选择如何执行此操作在此代码中使用一些特定元素,我正在使用 HTML Jerico解析器。请帮助我,那些在阅读代码时遇到问题的人我很抱歉,但你是程序员,我以为你喜欢这个。
3-如何从标签中获取href链接。
<div class='bestMFdtl2 '>
<div class='tBrd btBrd tbg'>
<div class='FL eqTle2 wd_182 rtBrd PL10 PR10'><a href='' class='bl_11'><strong></strong></a></div>
<div class='FL eqTle wd_65 rtBrd PL5 PR5' align='center'><strong>some data</strong></div>
<div class='FL eqTle wd_83 rtBrd' align='center'>
<div class='btBrd'><strong>some data</strong> <span style='font-size:8px;'>some data</span></div>
<div class='PT3'>some data</div>
</div>
<div class='FL eqTle wd_46 rtBrd btBrd' align='center'><strong>some data</strong></div>
<div class='FL eqTle rtBrd'>
<div align='center' class='btBrd'><strong>some data</strong></div>
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td align='center' width='56' height='20' class='rtBrd'><strong>some data <sup>some data</sup></strong></td>
<td align='center' width='56' class='rtBrd'><strong>some data <sup> </sup></strong></td>
<td align='center' width='56' class='rtBrd'><strong>some data <sup> </sup></strong></td>
<td align='center' width='56' class='rtBrd'><strong>some data<sup> </sup></strong></td>
<td align='center' width='56' class='rtBrd'><strong>some data<sup>*</sup></strong></td>
<td align='center' width='56'><strong>some data <sup>*</sup></strong></td>
</tr>
</table>
</div>
<div class='FL btBrd' style='width:43px;'></div>
<div class='CL'></div>
</div>
<div class='equityN2'>
<table cellspacing='0' cellpadding='0' style='margin-top:5px;'><tr>
<td width='185'><div align='left'><a class='b-12' title='BNP Paribas Equity Fund (G)' href=''>Want to access</a> </div></td>
<td width='70' nowrap=''><a href='' class='dgrey_12' target='_blank'>Rank 1</a><br><a href='/mf/crisil_methodology/' target='_blank'><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span></a></td>
<td width='70' style='text-align:right;'>127.22</td>
<td width='40' style='text-align:right;'>42.03</td>
<td class='#000000' width='48' style='text-align:right;'>--</td>
<td class='grn' width='48' style='text-align:right;'>3.0</td>
<td class='grn' width='48' style='text-align:right;'>10.3</td>
<td class='grn' width='48' style='text-align:right;'>6.6</td>
<td class='grn' width='50' style='text-align:right;'>18.9</td>
<td class='grn' width='50' style='text-align:right;'>5.6</td>
<td><A href='want to access' title='Download Form' target='_new' class='mfToolt'><img src='' alt=''></A></td>
</tr><tr>
<td width='185'><div align='left'><a class='b-12' title='' href='/'>want to access</a> </div></td>
<td width='70' nowrap=''><a href='' class='dgrey_12' target='_blank'>Rank 1</a><br><a href='/mf/crisil_methodology/' target='_blank'><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span><span class='star'></span></a></td>
<td width='70' style='text-align:right;'>105.26</td>
<td width='40' style='text-align:right;'>12.37</td>
<td class='grn' width='48' style='text-align:right;'>0.7</td>
<td class='grn' width='48' style='text-align:right;'>3.1</td>
<td class='grn' width='48' style='text-align:right;'>8.8</td>
<td class='grn' width='48' style='text-align:right;'>3.6</td>
<td class='grn' width='50' style='text-align:right;'>16.1</td>
<td class='grn' width='50' style='text-align:right;'>5.8</td>
<td><A href='want to access' title='Download Form' target='_new' class='mfToolt'><img src='' alt=''></A></td>
</tr>
鉴于评论,我相信这就是你所追求的。
var x = document.getElementsByClassName("bestMFdt12");
for (var i = 0; i < x.length; i++){
var x2 = x[i].getElementsByClassName("b-12");
for (var j = 0; j < x2.length; j++) {
//Do something with the elements, access them with "x2[j]", these loops will go through every element within both classes and allow you to process them
//Example:
var current = x2[j];
}
}
这应该得到所有"bestMFdt12"元素的数组,并且对于每个元素,在里面搜索任何"b-12"元素。在我放置示例的位置,您可以添加代码来处理这些元素。