Search code examples
pythonseleniumlinkedin-api

how to get the src attribute of a LinkedIn multiple profiles using selenium


Python code

sign_in_button1=driver.find_element_by_xpath('''/html/body/div[8]/div[3]/div/div/div/div/div[2]/main/div[1]/section/div[2]/div[1]/div[1]/div/div/img''')
src = sign_in_button1.get_attribute('src')
print(src)

I am trying to retrieve the src attribute of LinkedIn users just by putting their LinkedIn profile URL, The problem is that I do not want to use find_element_by_xpath, because of this I have to constantly change the XPath for different profiles which make is it too tedious and unconventional. Please suggest me how can I make it dynamic For eg: As soon as I put the LinkedIn URL I get the respective src attribute of the image


Solution

  • You can use the class name that contains the same phrase:

    driver.find_element_by_xpath("//img[contains("@class, 'presence-entity__image presence- 
    entity__image')]")
    

    And then you can retrieve the src as you did.