Yaron Koresh commited on
Commit
c6e402b
·
verified ·
1 Parent(s): db97e79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -35,14 +35,14 @@ def translate(text,lang):
35
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
36
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
37
  ]
38
- resp = requests.post(
39
- url = f"https://dictionary.cambridge.org/translate/?languageFrom=auto&txtTrans={text}&languageTo={lang}",
40
  headers = {
41
  'User-Agent': random.choice(user_agents)
42
  }
43
  )
44
  print(resp)
45
- translated = fromstring(resp.content).xpath('//div[@id="translate-tool__result"')[0].text().strip()
46
  return re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
47
 
48
  def generate_random_string(length):
 
35
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15',
36
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
37
  ]
38
+ resp = requests.get(
39
+ url = f'https://www.google.com/search?q=translate%20to%20{lang}:{text}'
40
  headers = {
41
  'User-Agent': random.choice(user_agents)
42
  }
43
  )
44
  print(resp)
45
+ translated = fromstring(resp.content).xpath('//span[@lang')[0].text().strip()
46
  return re.sub(f'[{string.punctuation}]', '', re.sub('[\s+]', ' ', translated)).lower().strip()
47
 
48
  def generate_random_string(length):