Yaron Koresh commited on
Commit
14525e0
·
verified ·
1 Parent(s): dad7330

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -54,7 +54,8 @@ def translate(text,lang):
54
  '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',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
- url = 'https://www.google.com/search?q=english%20translate%20'+text.replace(" ","%20")
 
58
 
59
  print(url)
60
 
@@ -71,10 +72,10 @@ def translate(text,lang):
71
  translated = text
72
 
73
  try:
74
- src_lang = html.xpath('//span[@class="source-language"]')[0].text_content().strip()
75
- trgt_lang = html.xpath('//span[@class="target-language"]')[0].text_content().strip()
76
- src_text = html.xpath('//pre[@id="tw-source-text"]/span')[0].text_content().strip()
77
- trgt_text = html.xpath('//pre[@id="tw-target-text"]/span')[0].text_content().strip()
78
 
79
  if trgt_lang.lower() == lang.lower():
80
  translated = trgt_text
 
54
  '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',
55
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 13_1) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.1 Safari/605.1.15'
56
  ]
57
+ query_text = 'english%20translate%20'+text.replace(" ","%20")
58
+ url = f'https://www.google.co.il/search?q={query_text}&qo={query_text}'
59
 
60
  print(url)
61
 
 
72
  translated = text
73
 
74
  try:
75
+ src_lang = html.xpath('//*[@class="source-language"]')[0].text_content().strip()
76
+ trgt_lang = html.xpath('//*[@class="target-language"]')[0].text_content().strip()
77
+ src_text = html.xpath('//*[@id="tw-source-text"]/*')[0].text_content().strip()
78
+ trgt_text = html.xpath('//*[@id="tw-target-text"]/*')[0].text_content().strip()
79
 
80
  if trgt_lang.lower() == lang.lower():
81
  translated = trgt_text