我是Xpath的新手。虽然我可以在html
中看到它,但是通过JavaCode没有得到任何结果System.out.println("print page:"+ page.getByXPath("//li[@class='li_float row_basic_style v2_1 hide_rating_only row_li']//a[@class='product highlighted-link']").size());
我的htmlPage位于:
<div class="search-results-row v2_1 hide_rating_only " style="">
<div class="quick-view-pop-pos">
<a class="product highlighted-link" onclick="checkAndFirePixel(true, false, 3271456701,11108056,'psmjp',event,'http://adq.nextag.com/buyer/dyad/pixel.jsp?channel={channel}&ptitle={ptitle}&node={node}&click={click}'); " rel="nofollow" target="_blank" name="selected-link" data-productid="3271455821" data-ptitleid="3271456701" type="sliding" href="/norob/PtitleSeller.jsp?ptitle=3271456701&tag=4658550237&chnl=psmjp&ctx=8joC0vxcxc1w4BVH6xYuC3CohUNmSrdqeuy2crpK7LAifIbxriI6IM3KsmFmUoeYU6kL%2FvXoI6tM2JhxOUXS7DNoWQEar8YzsURb7k3Dcwvvr0mdU2zQsD4RCi3AezCID%2F6YI0JVyJ%2BJXPC5vhdtjN%2BcUWCp%2BNgPNqzTcq7JKMGlL4xnUcv1s%2FgS8uCu7C11AGYzjQwnYBmNzkYNbe%2FYN%2Bp2ByYCZgSjCtFwKziXCpeNN0QmIg3ml8dgDRM8lfiVc8u%2BpEVkawKZk6ck6ayJvvsvbI8WlweNICMRlXl5oo0FliOjuhpc%2FzU2wIp7Kidj4orbK7zwVOAWkyXe%2FmQXksfIzY5yP4F%2BS99danitsbeahRl0zlnv9t1d7qaW3p1OwWvldfGIllPQA%2B9egdICWkFHtUQzecTsdRUTwYm7y%2BHgf7kc1%2FSRLQWnKNKFuDq0yDfgVuJHgRQWfa1L%2FWJZWVOaFpDVQ5V6f%2BHQ%2BHnSPIPhB0DZbaKYyrSyo1Ps5CRSjHghu62AFl12vJ77vtJKC8uWbJHXXneMZg1v8F1d2x96eKp2G%2BpJUl%2Fo44PPthY%2BjYgGY271BT51NCQQv%2BSCAnlOEj6kPoTk3tIMcu7nyshjkPskQzNHppgvK5BivCs6%2BltFVlp47arxIqgKoO0vzdtOCUQ6OM1%2B4pOgUfWSvEsCHpo5%2F1ODw3WoUgedBpeM2VxxhU19AaEwJ%2BUiEf7uduOODbfveRlTd9ilUij%2BZOy96dipaOWIXNURgg8UzYRVMLyfulybgiooU6wqfbUHW9TCMqmyWgKyiU0JSnUYSmqTp5lGxD5EnkpOFkYZD3oVE9vIL%2FQeHj4rS8NmcK7rpC2HDWs3DUtJlIbDgci5pmqf4lFQUasee0Dv0Kg7RqDE5KIQ7Bpz1rTMy85DxW8uUw%3D%3D">
</div>
<div id="card_border_no0" class="card_border"/>
</li>
<li id="product_no_1" class="li_float row_basic_style v2_1 hide_rating_only row_li">
返回0结果任何想法为什么?
答案 0 :(得分:0)
您可以使用下面带有id的div来编写更好的XPath选择器。
//div[id="card_border_no0"]/preceding::div[1]/a
首先选择下面的div,然后获取其前一个div及其子锚点。