擅长:python、mysql、java
<p>您可以执行以下操作:</p>
<ul>
<li>迭代“list header”元素</li>
<li>对于每个“list header”,获取<em>下面的同级</em>并收集“tags”(将这些<code>li</code>元素文本命名为“tags”),直到满足<code>lh</code>同级</li>
</ul>
<p>大致如下:</p>
<pre><code>for lh in driver.find_elements_by_xpath("//ul[@id='searchresults']//lh"):
restaurant = lh.text
tags = []
for element in lh.find_elements_by_xpath("./following-sibling::*"):
if element.tag_name == 'lh':
break
tags.append(element.text)
print(restaurant, tags)
</code></pre>