Python Forum
Why doesn't it show me anything in print?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why doesn't it show me anything in print?
#1
Why doesn't it show me anything in print?

import re
import html
from urllib import parse
import requests

GOOGLE_TRANSLATE_URL = 'http://translate.google.cn/m?q=%s&tl=%s&sl=%s'

def translate(text, to_language="auto", text_language="auto"):

    text = parse.quote(text)
    url = GOOGLE_TRANSLATE_URL % (text,to_language,text_language)
    response = requests.get(url)
    data = response.text
    expr = r'(?s)class="(?:t0|result-container)">(.*?)<'
    result = re.findall(expr, data)
    if (len(result) == 0):
        return ""

    return html.unescape(result[0])

print(translate("你吃饭了么?", "en","zh-CN")) #Chinese to English
print(translate("你吃饭了么&#xff1f;", "ja","zh-CN")) #Chinese to Japanese
print(translate("about your situation", "zh-CN","en")) #English to Chinese
print(translate("about your situation", "en","ro")) #English to Chinese
Reply


Messages In This Thread
Why doesn't it show me anything in print? - by Melcu54 - Sep-30-2022, 08:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PDF properties doesn't show created or modified date Pedroski55 4 2,498 Jun-19-2023, 08:09 AM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 2 2,241 Sep-12-2022, 10:19 PM
Last Post: Pedroski55
  PIL Image im.show() no show! Pedroski55 6 11,781 Feb-08-2022, 06:32 AM
Last Post: Pedroski55
  Why doesn't this print statement work? stylingpat 10 8,572 Mar-23-2021, 07:54 PM
Last Post: buran
  Line of code to show dictionary doesn't work MaartenRo 2 3,117 Jul-28-2020, 03:58 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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