Extract Company names from Experience Section LinkedIn extract python

Viewed 27

I need to extract the experience section and I need to scrape companies where he has worked(either previous or current) with python, I have tried but it is not working.

my code -

div = driver.find_element('div', class_='t-14 t-normal')
span = div.find_element('span', {'aria-hidden': 'true'})
text = span.get_text()
print(text)

Inspect element looks like -

this is just for a single company, btw all the inspect looks same for rest of the companies I checked.

image_for_inspect_element

<span class="t-14 t-normal">
    <span aria-hidden="true">
      <!---->
      "Financial Times . Full-time"
      <!---->
     </span>

link - https://www.linkedin.com/in/fred-thompson-8a892a19b/

So I just want to extract all the companies which are there in the inspect element. I am unable to do, it seems tough to apply a logic which will loop through all companies and get the names.

1 Answers

You are mixing Selenium syntax with BeautifulSoup syntax.
If you want to do this with Selenium your syntax should be as following:

elements = driver.find_elements(By.CSS_SELECTOR, ".t-14.t-normal span[aria-hidden='true']")
for element in elements:
    print(element.text)

However this will not work perfect since locators you are using here will match irrelevant elements too.

Related