<legend id='Kzif8'><style id='Kzif8'><dir id='Kzif8'><q id='Kzif8'></q></dir></style></legend>

  • <i id='Kzif8'><tr id='Kzif8'><dt id='Kzif8'><q id='Kzif8'><span id='Kzif8'><b id='Kzif8'><form id='Kzif8'><ins id='Kzif8'></ins><ul id='Kzif8'></ul><sub id='Kzif8'></sub></form><legend id='Kzif8'></legend><bdo id='Kzif8'><pre id='Kzif8'><center id='Kzif8'></center></pre></bdo></b><th id='Kzif8'></th></span></q></dt></tr></i><div id='Kzif8'><tfoot id='Kzif8'></tfoot><dl id='Kzif8'><fieldset id='Kzif8'></fieldset></dl></div>

    1. <tfoot id='Kzif8'></tfoot>

        <bdo id='Kzif8'></bdo><ul id='Kzif8'></ul>

        <small id='Kzif8'></small><noframes id='Kzif8'>

      1. TypeError:“WebElement"对象不是可迭代的错误

        时间:2023-10-08

        <tfoot id='iKsUH'></tfoot>
        • <bdo id='iKsUH'></bdo><ul id='iKsUH'></ul>
          1. <small id='iKsUH'></small><noframes id='iKsUH'>

            <i id='iKsUH'><tr id='iKsUH'><dt id='iKsUH'><q id='iKsUH'><span id='iKsUH'><b id='iKsUH'><form id='iKsUH'><ins id='iKsUH'></ins><ul id='iKsUH'></ul><sub id='iKsUH'></sub></form><legend id='iKsUH'></legend><bdo id='iKsUH'><pre id='iKsUH'><center id='iKsUH'></center></pre></bdo></b><th id='iKsUH'></th></span></q></dt></tr></i><div id='iKsUH'><tfoot id='iKsUH'></tfoot><dl id='iKsUH'><fieldset id='iKsUH'></fieldset></dl></div>

            <legend id='iKsUH'><style id='iKsUH'><dir id='iKsUH'><q id='iKsUH'></q></dir></style></legend>
              <tbody id='iKsUH'></tbody>
                  本文介绍了TypeError:“WebElement"对象不是可迭代的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从维基百科主页中提取所有链接,但此代码显示 TypeError: 'WebElement' object is not iterable error.

                  I am trying to extract all the links from wikipedia homepage but this code showing TypeError: 'WebElement' object is not iterable error.

                  import time
                  from selenium import webdriver
                  from selenium.webdriver.common.keys import Keys
                  
                  browser=webdriver.Chrome()
                  browser.get('https://en.wikipedia.org/wiki/Main_Page')
                  search=[]
                  search=browser.find_element_by_xpath('//*[@href]')
                  
                  
                  for ii in search:
                    print(ii.get_attribute('href'))
                  
                  time.sleep(4)
                  browser.close()  
                  

                  推荐答案

                  问题是你使用的 find_element_by_xpath 只返回一个 WebElement(不可迭代),find_elements_by_xpath 返回一个 WebElement 列表.

                  The problem is that you are using find_element_by_xpath which return only one WebElement (which is not iterable), the find_elements_by_xpath return a list of WebElements.

                  解决方法:将 find_element_by_xpath 替换为 find_elements_by_xpath

                  Solution: replace find_element_by_xpath with find_elements_by_xpath

                  参考:selenium-python 文档

                  这篇关于TypeError:“WebElement"对象不是可迭代的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MAC 上的 Selenium,消息:“chromedriver"可执行文件 下一篇:如何使用 Selenium 和 Python 绑定禁用日志记录

                  相关文章

                  最新文章

                1. <tfoot id='Cq6iz'></tfoot>

                  <legend id='Cq6iz'><style id='Cq6iz'><dir id='Cq6iz'><q id='Cq6iz'></q></dir></style></legend>
                2. <small id='Cq6iz'></small><noframes id='Cq6iz'>

                3. <i id='Cq6iz'><tr id='Cq6iz'><dt id='Cq6iz'><q id='Cq6iz'><span id='Cq6iz'><b id='Cq6iz'><form id='Cq6iz'><ins id='Cq6iz'></ins><ul id='Cq6iz'></ul><sub id='Cq6iz'></sub></form><legend id='Cq6iz'></legend><bdo id='Cq6iz'><pre id='Cq6iz'><center id='Cq6iz'></center></pre></bdo></b><th id='Cq6iz'></th></span></q></dt></tr></i><div id='Cq6iz'><tfoot id='Cq6iz'></tfoot><dl id='Cq6iz'><fieldset id='Cq6iz'></fieldset></dl></div>

                  • <bdo id='Cq6iz'></bdo><ul id='Cq6iz'></ul>