【问题标题】:Html Table data is returning "None"Html 表数据返回“无”
【发布时间】:2021-01-14 23:13:44
【问题描述】:

我正在使用 selenium webdriver 从这个 http://proxydb.net/?protocol=socks4&country=BD 中抓取代理地址。但是在尝试从表中抓取数据时,我得到了 "None" 。这是我的代码::

from selenium import webdriver

browser = webdriver.Chrome()
browser.get(
    'http://proxydb.net/?protocol=socks4&country=BD')
String = browser.find_element_by_xpath("//table/tbody/tr[1]/td[1]")
print(String.get_attribute('text'))
browser.quit()

这是输出:

C:\Users\Asus\Documents\Hello World>python -u "c:\Users\Asus\Documents\Hello World\Web Scraping\proxy\proxy1.py"

DevTools listening on ws://127.0.0.1:56478/devtools/browser/215c65c4-d3c5-4653-85c1-1f63ccde50ba
[36844:7508:0115/050206.852:ERROR:device_event_log_impl.cc(211)] [05:02:06.852] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[36844:7508:0115/050206.854:ERROR:device_event_log_impl.cc(211)] [05:02:06.854] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[36844:7508:0115/050206.870:ERROR:device_event_log_impl.cc(211)] [05:02:06.869] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
None

这里,为什么我会得到这个 [36844:7508:0115/050206.852:ERROR:device_event_log_impl.cc(211)] [05:02:06.852] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F) ? 以及如何解决这个“无”问题?

【问题讨论】:

    标签: python-3.x selenium xpath webdriver


    【解决方案1】:

    如果你想要一个元素的文本。首先等待元素加载,然后打印它的文本。

    wait = WebDriverWait(browser,10)
    elem = wait.until(EC.presence_of_element_located((By.XPATH,"//table/tbody/tr[1]/td[1]")))
    print(elem.text)
    

    输出

    203.188.245.98:52837
    

    导入

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait 
    from selenium.webdriver.support import expected_conditions as EC
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-22
      • 2011-01-10
      • 2015-09-29
      • 1970-01-01
      • 1970-01-01
      • 2020-04-11
      • 2012-04-18
      • 2017-12-27
      相关资源
      最近更新 更多