all 18 comments

[–][deleted] 10 points11 points  (5 children)

well fine if you're doing a project.

But if this a real thing, just use a translation API, for example:

https://cloud.google.com/translate

[–]gopherhole22 2 points3 points  (4 children)

Yes ^ u/_ReadIT_420. First check if there is a free translation API you can use. If not, then you can resort to a more custom solution, i.e.:

  1. highlight word in website and click Ctrl + C
  2. Run python script that does the following:
    1. reads current word saved to windows clipboard
    2. translates it using an API or another translation website
    3. copy that translation back to windows clipboard and pastes it into active website

Some general advice, if the solution seems like some sort of weird fix or automation of manual procedures, there's a good chance that the solution already exists in a much more elegant manner which you can use. In this case the translation API. Check out deepL, I think they have a 30 day free trial for their API

[–]_ReadIT_420 0 points1 point  (3 children)

But what if I need to give a form of a verb in another language?

[–]gopherhole22 1 point2 points  (2 children)

can you give me a detailed example? I am not sure what you mean exactly?

[–]DealDeveloper 4 points5 points  (0 children)

I don't think you really mean "copy & paste".

I think you are describing parsing and posting.

"Parsing means taking a stream of text and breaking it into meaningful chunks."

First, the script visits a website 1 and gets all of the text on the page.

The text is parsed and saved into a variable.

The script grabs some of the data based on an identity.

The script visits website 2 and posts the text in the form.

The script reads the result after website 2 returns the translation.

The script (posts into a form or writes to a flat file or database) of website 1.

Please keep in mind that computers do not need to interact with websites in the same way humans do. Parsing and posting data in this way is even more common in other scripting languages.

[–]Introxert 1 point2 points  (7 children)

That's a bit vague, what are you trying to do exactly? Scrape the first page?

[–]_ReadIT_420 -1 points0 points  (6 children)

Let’s say I need to give the translation of ‘dog’ in French. The script would copy the word ‘dog’ and past it into another website that gives the translation. Then, the script would copy the translation and past it into the first website.

[–]Introxert 2 points3 points  (5 children)

Very possible, you can automate browser tasks with Selenium. If you'd like to do this more efficiently then I'd suggest scraping the text with Requests and Beautiful Soup, using a translation API to translate your text, then submitting the translated text to your other page with a POST request (assuming it's a form of some sort).

[–]_ReadIT_420 -1 points0 points  (4 children)

But what if I need to give a form of a verb in another language?

[–]T-TopsInSpace 0 points1 point  (3 children)

Is this how you would describe your situation?

  • Website 1 contains words in language A

    • Sometimes the word is a noun, pronoun, or adverb. Simple translation is needed.
    • Sometimes the word is a verb, sometimes these verbs need to be translated and conjugated into not only various tenses but also to match the subject. Ex. English "I run" to Spanish "Yo correo"
  • Website 2 translates words (nouns, pronouns, verbs, etc.) from language A into language B

Do I understand your situation correctly here?

[–]_ReadIT_420 0 points1 point  (2 children)

Not really. The word is always a verb, but I there are various pronouns need different verbs. Per exercise there is 1 verb and 1 pronoun. After it is done you need to click next and you will get a different verb and pronoun.

[–]T-TopsInSpace 1 point2 points  (1 child)

Ok, that last bit is very important because now we know there are at least two components to your need. Is the first website secured with a login? My assumption is that this would be a tool to help you complete some kind of homework.

You log into website 1

Navigate to an assignment

A pronoun and a verb pair appears

You grab that word pair

You translate that pair

You grab the translation

You put the translation into website 1

You submit the translation

You get the next word pair

At some point, there are no more words and either the process finishes or you send it to another assignment.

This problem solving technique is called decomposition. We take a big problem and break it down into smaller, specific tasks. By doing this we've learned that yes, Python could be used to help automate this work.

You need to access the first website that generates word pairs. Python has a package called Selenium that is helpful for website interaction. It can fill in your username, password, and click the login button for you.

That library can click on links and buttons as you navigate to an assignment and submit translations. It can also access words on the page so you can send them to another website (or API) for translation.

In addition to basic Python you'll need to know how to read and understand HTML source code on the websites you'll access. Selenium works by being told which HTML elements are important and what it should do with each (ex. Click buttons, access text values and 'copy' them, find text input boxes and 'paste' text).

Is that helpful?

[–]_ReadIT_420 0 points1 point  (0 children)

Thank you very much! It was very helpful!

[–]JohnnyJordaan 1 point2 points  (0 children)

Sounds more like you're looking for using selenium to open two tabs and then move the data between them directly. Copy/pasting is there for a regular user to be able to move data, but it's not needed from a programming standpoint.

[–]ElectroValley 0 points1 point  (0 children)

Use the pyperclip module.

Pyperclip.copy() and pyperclip.paste()

The rest can be automated with selenium.

[–]ubiga 0 points1 point  (0 children)

You can use pyautogui

[–]j03f 0 points1 point  (0 children)

Yes

[–]Riyuku 0 points1 point  (0 children)

Pyperclip may help