Python Forum
Regex: a string does not starts and ends with the same character
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regex: a string does not starts and ends with the same character
#6
I find the solution. The regex, was trying to translate all the inner contents of the tags, however you the content part of the meta tag isn't inner content. I had to make a separate check to see if it was a meta tag, And then did translation specifically for the meta tag under that check.

So, after those regex, you I should add this code:

 for pattern in patterns:
                for x in re.finditer(pattern, page):
                    updated = True
                    new = x.group(0)
                    soup = BeautifulSoup(new, 'html.parser')
                    if pattern != pattern4:
                        recursively_translate(soup)
                    else:
                        meta = soup.find('meta')
                        meta['content'] = translator.translate(meta['content'], dest=destination_language).text
                    soup = soup.encode(formatter=UnsortedAttributes()).decode('utf-8')
                    page = page.replace(new, soup)
Reply


Messages In This Thread
RE: Regex: a string does not starts and ends with the same character - by Melcu54 - Jul-04-2021, 07:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Move column to the right if it starts with a letter mfernandes 0 709 Oct-25-2022, 11:22 AM
Last Post: mfernandes
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,454 Sep-27-2022, 01:38 PM
Last Post: buran
  pywin32: Outlook connection ends with 'operation aborted' on one machine tstone 0 2,474 May-03-2022, 04:29 AM
Last Post: tstone
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,857 Feb-18-2022, 01:29 PM
Last Post: pstein
  [solved] unexpected character after line continuation character paul18fr 4 3,532 Jun-22-2021, 03:22 PM
Last Post: deanhystad
  threadlocals are garbage collected before thread ends akv1597 0 1,841 Mar-09-2021, 12:13 PM
Last Post: akv1597
  Running a few lines of code as soon as my timer ends nethatar 3 2,463 Feb-26-2021, 01:02 PM
Last Post: jefsummers
  '|' character within Regex returns a tuple? pprod 10 5,735 Feb-19-2021, 05:29 PM
Last Post: eddywinch82
  Writing to file ends incorrectly project_science 4 2,784 Jan-06-2021, 06:39 PM
Last Post: bowlofred
  Help getting a string out of regex matt_the_hall 4 2,333 Dec-02-2020, 01:49 AM
Last Post: matt_the_hall

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020