1

I'm trying to get the current designation of a LinkedIn profile list using Python Selenium. I want the part after the 'Current:' and the 'Summary:'.

enter image description here

Here's the HTML:

<div class="linked-area flex-1 cursor-pointer">
  
        <p class="entity-result__summary entity-result__summary--2-lines t-12 t-black--light ">
          <!---->Current: Full Stack Software<span class="white-space-pre"> </span>
<strong><!---->Developer<!----></strong><span class="white-space-pre"> </span>at GE Healthcare<!---->
        </p>
      
</div>

I tried this:

currentDsgn = []
currentDesignations = browser.find_elements_by_class_name('linked-area flex-1')
    print(currentDesignations)

    for currentDesignation in currentDesignations:
        print(currentDesignation)
        currentDsgn.append(currentDesignation.text.strip())

But I got an empty list.

1 Answer 1

1

try this xpath instead :

//div[contains(@class, 'linked-area')]/p[contains(@class, 'entity-result__summary')]

and use it like it below :

currentDesignations  = browser.find_elements_by_xpath("//div[contains(@class, 'linked-area')]/p[contains(@class, 'entity-result__summary')]")
for currentDesignation in currentDesignations:
   print(currentDesignation.get_attribute('innerHTML'))
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, this worked! Instead of starting with div class 'linked'area' what if we directly go to p class 'entity-result__summary'?
Yes @ShridharK we can do that. Just make sure that in element structure (When you press F12) and when you use the mentioned xpath, your desired elements should be highlighted
And can we write the code without using the 'contains' keyword? Something like: @class = 'linked-area' or @class = 'entity-result-summary'?
No we cannot. If we write @class = 'linked-area Selenium will look for exact match, we wanted to pass sub part of the class hence we used contains
This makes sense

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.