D
D
dance_and_programmiruy2020-06-05 09:46:54
Python
dance_and_programmiruy, 2020-06-05 09:46:54

How to right click with selenium?

Good afternoon everyone. I am writing a Python script that parses this channel: https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-14...

Tell me , how can I parse a link to a publication? Just for publication. If you right-click on a post and click on "share link", the link will be saved to your clipboard. Tell me, how can I set up the parser so that it clicks RMB on each publication, clicks on "share link" and saves this saved link in the clipboard to the list?

5ed954ccc6c4b287890448.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Yakushenko, 2020-06-05
@dance_and_programmiruy

No way. All data in the messenger comes via a web socket, nothing is stored on the page, Selenium does not work with the clipboard.

S
ScriptKiddo, 2020-06-05
@ScriptKiddo

If you can’t do without a RMB click

import clipboard

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec

driver = webdriver.Chrome()
# Загружаем страницу

driver.get("https://yandex.ru/chat/#/chats/1%2F0%2Fccb05ef5-1472-4e50-a926-602807a6ef94")
balloons_xpath = "//div[contains(@class, 'yamb-message-balloon')]"
WebDriverWait(driver, 10).until(ec.presence_of_all_elements_located((By.XPATH, balloons_xpath)))


# Выбираем посты в канале
balloons = driver.find_elements_by_xpath(balloons_xpath)

# Кликаем на пост #4
actionChains = ActionChains(driver)
actionChains.context_click(balloons[4]).perform()
get_link_text = 'Get message link'
driver.find_element_by_xpath(f"//span[text()='{get_link_text}']/..").click()

# Получаем буфер обмена
text = clipboard.paste()  # text will have the content of clipboard


print(text)
driver.quit()

OUT
https://yandex.ru/chat/#/join/33a66c77-0c4d-45be-80f6-cae89e95d765/1591340550272042

Process finished with exit code 0

It remains to add the algorithm for passing through all the necessary links / posts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question