Home > database >  Selenium img url to text
Selenium img url to text

Time:01-24

I'm having trouble with selenium

I'm making a scraper for glassdoor, and I'm having trouble getting the url of the company logo

<span ><img src="https://media.glassdoor.com/sql/5130433/studs-squarelogo-1642593020221.png" alt="Studs Logo" title="Studs Logo"></span>

I try with xpath is not work

try:
                    
                logo = driver.find_element_by_xpath('/html/body/div[3]/div/div/div[1]/div/div[2]/section/article/div[1]/ul/li[1]/div[1]/a/span/img').link
            except NoSuchElementException:
                logo = -1

any help will be very valuable to me

CodePudding user response:

Try with:

driver.find_element_by_xpath('//span[contains(@class, "job-search-key")]/img').get_attribute('src')

Edited: as another responder mentioned, you should use get_attribute() on the resulted element, since the image url is actually an attribute of the img tag, not its actual text content.

CodePudding user response:

You should use get_attribute method for this purpose:

try:
    logo = driver.find_element(By.XPATH, "//img[@title='Studs Logo']").get_attribute('src')
    print(logo)
except:
    pass
  •  Tags:  
  • Related