我正在尝试在 selenium 上解析此代码,并且基本上想要列表中的第一项,即“product one-col new”!点击...
<ul id="product-list">
<li class="product one-col new">
<ul>
<li class="image" title="one item 5">
<a href="#product/0f37f703-ed9a-3d10-86c0-7d0c0fcdb9ec">
<img width="" height="" alt="" src="/content/images/ProductImages/you-are-here/3/E/4/3E42561208174E6FBC81A10CDAE48659.jpg"></img>
<span class="new"> … </span>
<span class="hover"></span>
</a>
<p class="retailer">
CHECK ME
</p>
<p class="brand"></p>
</li>
<li class="price"> … </li>
<li class="name" title="one item 5"> … </li>
<li class="first-seen"> … </li>
</ul>
</li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
<li class="product one-col new"> … </li>
我试过这个
browser.find_element_by_css_selector("ul[id='product-list'] li:nth-of-type(1)").click()
但它不起作用?
任何的想法?
更新:
正确的路径是
browser.find_element_by_css_selector("ul#product-list > :first-child").text