Home > Net >  How can I extract HREF content with selenium?
How can I extract HREF content with selenium?

Time:01-09

I'm not able to extract the HREF from the page I'm doing webscraping.

I indicated the path where the HREF element exists but the return is not what was expected, here is the terminal output message:

<selenium.webdriver.remote.webelement.WebElement (session="66ad657afa9fee5c8b32ff8f48f9d335", element="3ecf1a1d-ddf0-4ce9-b07f-d3e405ec4e08")>

I need to extract the link from the group profiles.

driver.get(link)
driver.maximize_window()
sleep(5)

input_email = driver.find_element(By.ID, "email").send_keys(email)
input_senha = driver.find_element(By.ID, "pass").send_keys(senha, Keys.ENTER)
sleep(10)

linkdosperfis = driver.find_elements(By. XPATH, "//body[1]/div[1]/div[1]/div[1]/div[1]/div[3]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[1]/div[1]/div[4]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[13]/div[1]/div[2]/div[1]/div/div/div/div/span/span/a")

for perfis in linkdosperfis:
    perfis.get_attribute("href")
    sleep(2)
    print(perfis)

CodePudding user response:

save result of get_attribute to variable href then print it out

for anchor in linkdosperfis:
    href = anchor.get_attribute["href"]
    print(href)
  • Related