Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates in person.py (css classnames and other changes) #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 51 additions & 16 deletions linkedin_scraper/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_experiences(self):
self.scroll_to_bottom()
main_list = self.wait_for_element_to_load(name="pvs-list", base=main)
for position in main_list.find_elements(By.XPATH,"li"):
position = position.find_element(By.CLASS_NAME,"pvs-entity")
position = position.find_element(By.CLASS_NAME,"pvs-entity--padded")
company_logo_elem, position_details = position.find_elements(By.XPATH,"*")

# company elem
Expand All @@ -130,20 +130,34 @@ def get_experiences(self):
if len(outer_positions) == 4:
position_title = outer_positions[0].find_element(By.TAG_NAME,"span").text
company = outer_positions[1].find_element(By.TAG_NAME,"span").text
if "·" in company:
company = company.split(" ·", 1)[0]
work_times = outer_positions[2].find_element(By.TAG_NAME,"span").text
location = outer_positions[3].find_element(By.TAG_NAME,"span").text
work_times = outer_positions[2].find_element(By.TAG_NAME,"span").text
location = outer_positions[3].find_element(By.TAG_NAME,"span").text
elif len(outer_positions) == 3:
if "·" in outer_positions[2].text:
position_title = outer_positions[0].find_element(By.TAG_NAME,"span").text
company = outer_positions[1].find_element(By.TAG_NAME,"span").text
if "·" in company:
company = company.split(" ·", 1)[0]
work_times = outer_positions[2].find_element(By.TAG_NAME,"span").text
location = ""
else:
position_title = ""
company = outer_positions[0].find_element(By.TAG_NAME,"span").text
if "·" in company:
company = company.split(" ·", 1)[0]
work_times = outer_positions[1].find_element(By.TAG_NAME,"span").text
location = outer_positions[2].find_element(By.TAG_NAME,"span").text

elif len(outer_positions) == 2:
position_title = ""
company = outer_positions[0].find_element(By.TAG_NAME,"span").text
if "·" in company:
company = company.split(" ·", 1)[0]
work_times = outer_positions[1].find_element(By.TAG_NAME,"span").text
location = ""
times = work_times.split("·")[0].strip() if work_times else ""
duration = work_times.split("·")[1].strip() if len(work_times.split("·")) > 1 else None

Expand All @@ -155,31 +169,47 @@ def get_experiences(self):
for description in descriptions:
res = description.find_element(By.TAG_NAME,"a").find_elements(By.XPATH,"*")
position_title_elem = res[0] if len(res) > 0 else None
work_times_elem = res[1] if len(res) > 1 else None
location_elem = res[2] if len(res) > 2 else None


#work_times_elem = res[1] if len(res) > 1 else None
#location_elem = res[2] if len(res) > 2 else None
if len(res) > 1 and "·" in res[1].text:
work_times_elem = res[1]
location_elem = res[2] if len(res) > 2 else None
elif len(res) > 2 and "·" in res[2].text:
work_times_elem = res[2]
location_elem = res[3] if len(res) > 3 else None
else:
location_elem = res[3] if len(res) > 3 else None

try:
position_description = description.find_element(By.CLASS_NAME,"pvs-list__outer-container").find_element(By.XPATH,'.//ul/li[1]').find_element(By.XPATH,".//span[1]").text
except NoSuchElementException:
position_description = ""
location = location_elem.find_element(By.XPATH,"*").text if location_elem else None
position_title = position_title_elem.find_element(By.XPATH,"*").find_element(By.TAG_NAME,"*").text if position_title_elem else ""
work_times = work_times_elem.find_element(By.XPATH,"*").text if work_times_elem else ""
times = work_times.split("·")[0].strip() if work_times else ""
duration = work_times.split("·")[1].strip() if len(work_times.split("·")) > 1 else None
from_date = " ".join(times.split(" ")[:2]) if times else ""
to_date = " ".join(times.split(" ")[3:]) if times else ""
#from_date = " ".join(times.split(" ")[:2]) if times else ""
#to_date = " ".join(times.split(" ")[3:]) if times else ""
if times != "":
from_date = times.split(" ")[times.split(" ").index("-")-1] if len(times.split(" "))>3 else times.split(" ")[0]
to_date = times.split(" ")[-1]

experience = Experience(
position_title=position_title,
from_date=from_date,
to_date=to_date,
duration=duration,
location=location,
description=description,
#description=description,
description=position_description,
institution_name=company,
linkedin_url=company_linkedin_url
)
self.add_experience(experience)
else:
description = position_summary_text.text if position_summary_text else ""
#description = position_summary_text.text if position_summary_text else ""
description = position_summary_text.find_element(By.XPATH,'.//ul/li[1]').find_element(By.XPATH,".//span[1]").text if position_summary_text else ""

experience = Experience(
position_title=position_title,
Expand All @@ -201,7 +231,8 @@ def get_educations(self):
self.scroll_to_half()
self.scroll_to_bottom()
main_list = self.wait_for_element_to_load(name="pvs-list", base=main)
for position in main_list.find_elements(By.CLASS_NAME,"pvs-entity"):
#for position in main_list.find_elements(By.CLASS_NAME,"pvs-entity"):
for position in main_list.find_elements(By.CLASS_NAME,"pvs-entity--padded"):
institution_logo_elem, position_details = position.find_elements(By.XPATH,"*")

# company elem
Expand All @@ -214,19 +245,23 @@ def get_educations(self):
outer_positions = position_summary_details.find_element(By.XPATH,"*").find_elements(By.XPATH,"*")

institution_name = outer_positions[0].find_element(By.TAG_NAME,"span").text
degree = outer_positions[1].find_element(By.TAG_NAME,"span").text
#degree = outer_positions[1].find_element(By.TAG_NAME,"span").text

if len(outer_positions)>1:
degree = outer_positions[1].find_element(By.TAG_NAME,"span").text
else:
degree="NA"

if len(outer_positions) > 2:
times = outer_positions[2].find_element(By.TAG_NAME,"span").text
if times != "":
from_date = times.split(" ")[times.split(" ").index("-")-1] if len(times.split(" "))>3 else times.split(" ")[0]
to_date = times.split(" ")[-1]

from_date = " ".join(times.split(" ")[:2])
to_date = " ".join(times.split(" ")[3:])
else:
from_date = None
to_date = None



description = position_summary_text.text if position_summary_text else ""

education = Education(
Expand Down