Asir Shahriar Roudra
Asir Shahriar Roudra

Reputation: 360

Html Table data is returning "None"

I am working to scrape proxy addresses using selenium webdriver from this http://proxydb.net/?protocol=socks4&country=BD . But while trying to scrape data from table I'm getting "None" . Here is my code::

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()

Here is the output:

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

Here, why am I getting this [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) ? and how to solve this "None" problem ?

Upvotes: 0

Views: 91

Answers (1)

Arundeep Chohan
Arundeep Chohan

Reputation: 9969

If you want the text of an element. First you wait for the element to load and then you print it's text.

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

Outputs

203.188.245.98:52837

Import

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

Upvotes: 1

Related Questions