Yaron Koresh commited on
Commit
758f177
·
verified ·
1 Parent(s): 61582d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -33,20 +33,27 @@ def translate(text,lang):
33
  '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',
34
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
35
  ]
36
- html_str = requests.get(
37
- url = "https://www.bing.com/ttranslatev3?isVertical=1&&IG=25FEDD45BDB744CF85D101C01E6596C0&IID=translator.5026",
38
- json = {
39
- 'fromLang': auto-detect,
 
 
 
 
 
40
  'to': lang,
41
- 'token': MLfPKZhAXMWZirPdlpeEfN8DB58dZKR-,
42
- 'key': 1722119087131,
43
- 'text': text
44
- 'tryFetchingGenderDebiasedTranslations': true
45
  },
46
  headers = {'User-Agent': random.choice(user_agents)}
47
- ).content
48
- root = fromstring(html_str)
49
- translated = root.xpath(f'//textarea')[1].text().strip()
 
 
50
  return translated
51
 
52
  def generate_random_string(length):
 
33
  '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',
34
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
35
  ]
36
+ resp = requests.post(
37
+ url = "https://www.bing.com/ttranslatev3",
38
+ params = {
39
+ 'isVertical': '1',
40
+ 'IG': '25FEDD45BDB744CF85D101C01E6596C0',
41
+ 'IID': 'translator.5026'
42
+ },
43
+ data = {
44
+ 'fromLang': 'auto-detect',
45
  'to': lang,
46
+ 'token': 'MLfPKZhAXMWZirPdlpeEfN8DB58dZKR-',
47
+ 'key': '1722119087131',
48
+ 'text': text,
49
+ 'tryFetchingGenderDebiasedTranslations': 'true'
50
  },
51
  headers = {'User-Agent': random.choice(user_agents)}
52
+ )
53
+ print(resp)
54
+ jsn = resp.json()
55
+ print(jsn)
56
+ translated = jsn[0]["translations"][0]["text"]
57
  return translated
58
 
59
  def generate_random_string(length):