python - Extract text from webpage with Selenium -
i attempting extract ip addresses webpage using following code (snippet).
ips = driver.find_elements_by_xpath("//span[contains(text(), '10.')]") print(ips)
the html element(s) this:
<span style="padding: 1px 4px;float:left;">10.20.20.20</span>
inspect >> copy xpath returns:
//*[@id="t1700010887"]/tbody/tr[2]/td[1]/nobr/span
but code prints looks generic selenium code:
[<selenium.webdriver.remote.webelement.webelement (session="7885f3a61de714f2cb33 b23d03112ff2", element="0.5496921740104628-2")>, <selenium.webdriver.remote.webe lement.webelement (session="7885f3a61de714f2cb33b23d03112ff2", element="0.549692 1740104628-3")>, <selenium.webdriver.remote.webelement.webelement (session="7885 f3a61de714f2cb33b23d03112ff2", element="0.5496921740104628-4")>]
how can print actual ip of 10.20.20.20?
when using selenium's element finding methods, you're retrieving webelement object. want element's text, can retrieve via text
attribute of webelement object. also, find_elements_by_xpath
method returns list of webelements, need iterate it:
ips = driver.find_elements_by_xpath("//span[contains(text(), '10.')]") ip in ips: print(ip.text)
Comments
Post a Comment