Python Requests

There’s a web that checks if a text (in Catalan) has mistakes. I want to write a code to write a string into the textarea and get the response, but I don’t know how to do it.
That’s what I have until now:

import requests
from bs4 import BeautifulSoup

text_to_check = "Aixo es un text amb faltes"

response = requests.post("https://www.softcatala.org/corrector/", data={"text": text_to_check})

# Parse the HTML code
soup = BeautifulSoup(response.text, 'html.parser')

# Print the HTML code
#print(soup.prettify())

# Split the HTML code into a list of lines
lines = str(soup).split('\n')

# Iterate over the lines and print each line with the line number
#for i, line in enumerate(lines):
#  Nline = f'{i+1}: {line}'
#  print(Nline)

# --- search engine ----
for line in lines:
  if 'text_to_check' in line:
    print(line)

Could anyone check it and help me to do it? I also accept a JavaScript version, because my intention is make it work with IOS shortcuts.

Thanks :heart:

2 Likes

In short, do you want to get input?

If you want to get an input, what is your current setup? Are you using flask?
(A link to your repl will be helpful)

P.S. if you want to use js, you can go with nodejs template

1 Like

A simple demo of reading and changing text in a textarea using JavaScript:

<textarea id="editor"></textarea>
<script type="text/javascript">
    const editor = document.getElementById("editor");
    const phraseToFind = "Hello world!";
    const replacement = "Replaced!";
    
    editor.addEventListener("click", function() {
        const lines = editor.value.split("\n");
        for (let i = 0; i < lines.length; i++) {
            if (lines[i].includes(phraseToFind)) {
                lines[i] = lines[i].replace(phraseToFind, replacement);
            }
        }
        editor.value = lines.join("\n");
    });
</script>