Skip to content

Commit

Permalink
Merge pull request #93 from DirectRoot/timing-fixes
Browse files Browse the repository at this point in the history
Timing fixes
  • Loading branch information
joeyism authored Apr 13, 2021
2 parents fed3399 + 9e7c5b9 commit f499086
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ __pycache__
*.pyc
chromedriver
.DS_Store
.vscode/
.env/
2 changes: 1 addition & 1 deletion linkedin_scraper/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def login(driver, email=None, password=None):
password_elem.send_keys(password)
password_elem.submit()

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "profile-nav-item")))
element = WebDriverWait(driver, 300).until(EC.presence_of_element_located((By.ID, "profile-nav-item")))
21 changes: 11 additions & 10 deletions linkedin_scraper/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class Person(Scraper):

__TOP_CARD = "pv-top-card"
__WAIT_FOR_ELEMENT_TIMEOUT = 5

def __init__(
self,
Expand Down Expand Up @@ -90,7 +91,7 @@ def scrape(self, close_on_complete=True):

def _click_see_more_by_class_name(self, class_name):
try:
_ = WebDriverWait(self.driver, 3).until(
_ = WebDriverWait(self.driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located((By.CLASS_NAME, class_name))
)
div = self.driver.find_element_by_class_name(class_name)
Expand All @@ -102,7 +103,7 @@ def scrape_logged_in(self, close_on_complete=True):
driver = self.driver
duration = None

root = WebDriverWait(driver, 3).until(
root = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located(
(
By.CLASS_NAME,
Expand All @@ -114,7 +115,7 @@ def scrape_logged_in(self, close_on_complete=True):

# get about
try:
see_more = WebDriverWait(driver, 3).until(
see_more = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located(
(
By.XPATH,
Expand All @@ -124,7 +125,7 @@ def scrape_logged_in(self, close_on_complete=True):
)
driver.execute_script("arguments[0].click();", see_more)

about = WebDriverWait(driver, 3).until(
about = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located(
(
By.XPATH,
Expand All @@ -150,7 +151,7 @@ def scrape_logged_in(self, close_on_complete=True):
self._click_see_more_by_class_name("pv-experience-section__see-more")

try:
_ = WebDriverWait(driver, 3).until(
_ = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located((By.ID, "experience-section"))
)
exp = driver.find_element_by_id("experience-section")
Expand Down Expand Up @@ -207,7 +208,7 @@ def scrape_logged_in(self, close_on_complete=True):
## Click SEE MORE
self._click_see_more_by_class_name("pv-education-section__see-more")
try:
_ = WebDriverWait(driver, 3).until(
_ = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located((By.ID, "education-section"))
)
edu = driver.find_element_by_id("education-section")
Expand Down Expand Up @@ -245,7 +246,7 @@ def scrape_logged_in(self, close_on_complete=True):
# get interest
try:

_ = WebDriverWait(driver, 3).until(
_ = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located(
(
By.XPATH,
Expand All @@ -268,7 +269,7 @@ def scrape_logged_in(self, close_on_complete=True):

# get accomplishment
try:
_ = WebDriverWait(driver, 3).until(
_ = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located(
(
By.XPATH,
Expand All @@ -294,7 +295,7 @@ def scrape_logged_in(self, close_on_complete=True):
# get connections
try:
driver.get("https://www.linkedin.com/mynetwork/invite-connect/connections/")
_ = WebDriverWait(driver, 5).until(
_ = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located((By.CLASS_NAME, "mn-connections"))
)
connections = driver.find_element_by_class_name("mn-connections")
Expand Down Expand Up @@ -327,7 +328,7 @@ def scrape_not_logged_in(self, close_on_complete=True, retry_limit=10):

# get experience
try:
_ = WebDriverWait(driver, 3).until(
_ = WebDriverWait(driver, self.__WAIT_FOR_ELEMENT_TIMEOUT).until(
EC.presence_of_element_located((By.CLASS_NAME, "experience"))
)
exp = driver.find_element_by_class_name("experience")
Expand Down

0 comments on commit f499086

Please sign in to comment.