Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
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 |
-
|
|
|
58 |
|
59 |
print(url)
|
60 |
|
@@ -71,10 +72,10 @@ def translate(text,lang):
|
|
71 |
translated = text
|
72 |
|
73 |
try:
|
74 |
-
src_lang = html.xpath('
|
75 |
-
trgt_lang = html.xpath('
|
76 |
-
src_text = html.xpath('
|
77 |
-
trgt_text = html.xpath('
|
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
|