Issue
I want to get the total number of pages from this linkedin post
url: https://www.linkedin.com/feed/update/urn:li:activity:7050104978106974208/
Here's the code that I tried to hover over the post and find the total pages
post_url = "https://www.linkedin.com/feed/update/urn:li:activity:7050104978106974208"
browser.get(post_url)
browser.execute_script("window.scrollBy(0,900)","")
achains = ActionChains(browser)
browser.find_element(By.XPATH, "//div[@class='ssplayer-actions center-actions']")
slider_dot = browser.find_element(By.XPATH, "//span[@aria-label='Total pages']")
achains.move_to_element(slider_dot).perform()
But this code is throwing and error Unable to locate element: {"method":"xpath","selector":"//div[@class='ssplayer-actions center-actions']"}
Can anyone please help me in solving this?
Solution
This is how you can try it,
(Here, I assume you're already logged in.)
The idea is that we need to switch to the iframe where the details of the attached document of the post lie.
And as you can see in the above HTML snippet, the attribute "aria-valuemax" holds the information about the maximum value of the page i.e. the number of pages in the document.
Here is the solution:
post_url = "https://www.linkedin.com/feed/update/urn:li:activity:7050104978106974208"
browser.get(post_url)
browser.execute_script("window.scrollBy(0,900);")
WebDriverWait(browser, 10).until(
EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[class='document-s-container__document-element document-s-container__document-element--loaded']")))
element = browser.find_element(By.CSS_SELECTOR, 'div.ssplayer-actions.center-actions')
pages = element.find_element(By.CSS_SELECTOR, 'div.ssplayer-progress-bar.meter-animated').get_attribute('aria-valuemax')
print(pages)
pages:
7
Answered By - Ajeet Verma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.