擅长:python、mysql、java
<p>您可以通过xpath查找元素,而不是通过xpath查找元素,然后进行迭代</p>
<p><strong>编辑</strong>-以下是我编写的代码,用于遍历页面上的链接列表</p>
<p>从selenium导入webdriver</p>
<p>chromePath=“chromedriver.exe”</p>
<p>driver=webdriver.Chrome(chromePath)</p>
<p>url=”http://books.toscrape.com/"</p>
<p>获取驱动程序(url)</p>
<p>elems=driver.find_elements_by_xpath(“//a[@href]”)</p>
<p>对于元素中的元素:</p>
<pre><code>print(elem.get_attribute("href"))
</code></pre>