AutID Posted October 18, 2014 Share Posted October 18, 2014 (edited) $URL = "http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el" Local $dData = InetRead($URL) ;ConsoleWrite($dData & @CRLF) Local $sData = BinaryToString($dData) ConsoleWrite($sData & @LF) String after converted from binary looks like this: ðáôñßäá. This apparently happens because the string contains French or greek(Bulgarian, Chinese and other languages which have non-latin characters) characters and it can't display them normally. What can I do about this? Edited October 18, 2014 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
FireFox Posted October 18, 2014 Share Posted October 18, 2014 (edited) Hi, Take a look at the flag parameter of the BinaryToString function. Br, FireFox. Edited October 18, 2014 by FireFox Link to comment Share on other sites More sharing options...
AutID Posted October 18, 2014 Author Share Posted October 18, 2014 Hi, already did. Not a solution. https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
AutID Posted October 18, 2014 Author Share Posted October 18, 2014 (edited) $sText = "http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el" hometown+ = the encoded string el at the end is the language - Greek auto in the middle is the auto detect which could be en that stands for English since I am translating English to other languages Edit: if I use winhttp instead of inetread and get the response text which converts the binary to string automatically, it gives the right characters Edited October 18, 2014 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
AutID Posted October 19, 2014 Author Share Posted October 19, 2014 (edited) Anyone up to this? It must be binarytostring function. I don't think inetread would mess it up. Again if I use winhttp instead of inetread it works good but I don't like this way because I am using winhttp object not the winhttp.au3 and I can not check errors or anythings since it is not pure autoit. Edited October 19, 2014 by AutID https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
AutID Posted October 20, 2014 Author Share Posted October 20, 2014 So isn't it so easy after all? https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
Iczer Posted October 20, 2014 Share Posted October 20, 2014 since almost always encoding is UTF8, you should decode it like this: $sHTMLsource = BinaryToString($sHTMLsource,4) ;to decode as UTF8 Spider001 1 Link to comment Share on other sites More sharing options...
AutID Posted October 21, 2014 Author Share Posted October 21, 2014 That much i know. However it won't work. You can try it with code in post 1 https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
Spider001 Posted October 21, 2014 Share Posted October 21, 2014 #include <MsgBoxConstants.au3> $URL = "http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el" Local $dData = InetRead($URL) ;ConsoleWrite($dData & @CRLF) Local $sData = BinaryToString($dData,4) MsgBox($MB_SYSTEMMODAL, "Title", $sData ) Link to comment Share on other sites More sharing options...
step887 Posted October 21, 2014 Share Posted October 21, 2014 #include <MsgBoxConstants.au3> $URL = "http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el" Local $dData = InetRead($URL) $len = BinaryLen($dData) Local $sData For $i = 1 to $len $sData &= ChrW(binaryMid($dData,$i,1)) next MsgBox($MB_SYSTEMMODAL, $len, $sData Link to comment Share on other sites More sharing options...
Gianni Posted October 21, 2014 Share Posted October 21, 2014 (edited) the correct output string should be like this: [[["πατρίδα","hometown","patrída",""]],,"en",,[["πατρίδα",[1],true,false,572,0,1,0]],[["hometown",1,[["πατρίδα",572,true,false],["γενέτειρά",276,true,false],["hometown",128,true,false],["πόλη",13,true,false],["την πατρίδα",8,true,false]],[[0,8]],"hometown"]],,,[["en"]],5] it seems that none of the above post attempts produces such string please check before posting Edited October 21, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Solution trancexx Posted October 21, 2014 Solution Share Posted October 21, 2014 As an alternative, you can always do something like this: #include "WinHttp.au3" MsgBox(4096, "", GoogleTranslate("hometown", "el")) Func GoogleTranslate($sString, $sTo, $sFrom = "auto") Local $hOpen = _WinHttpOpen("Mozilla/5.0") Local $hConnect = _WinHttpConnect($hOpen, "https://translate.google.com") Local $sRead = _WinHttpSimpleSSLRequest($hConnect, Default, "translate_a/t?client=t&sl=" & $sFrom & "&text=" & __WinHttpURLEncode($sString) & "&tl=" & $sTo) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return $sRead EndFunc AutID 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
step887 Posted October 21, 2014 Share Posted October 21, 2014 (edited) It appears that it is how Inetread is pulling down the data, the same happens with inetget. The solution that tracexx posted works. Edited October 21, 2014 by step887 Link to comment Share on other sites More sharing options...
Gianni Posted October 21, 2014 Share Posted October 21, 2014 ....... Again if I use winhttp instead of inetread it works good but I don't like this way because I am using winhttp object not the winhttp.au3 and I can not check errors or anythings since it is not pure autoit. how do you do it? ...... The solution that tracexx posted works. as always... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
AutID Posted October 21, 2014 Author Share Posted October 21, 2014 As an alternative, you can always do something like this: #include "WinHttp.au3" MsgBox(4096, "", GoogleTranslate("hometown", "el")) Func GoogleTranslate($sString, $sTo, $sFrom = "auto") Local $hOpen = _WinHttpOpen("Mozilla/5.0") Local $hConnect = _WinHttpConnect($hOpen, "https://translate.google.com") Local $sRead = _WinHttpSimpleSSLRequest($hConnect, Default, "translate_a/t?client=t&sl=" & $sFrom & "&text=" & __WinHttpURLEncode($sString) & "&tl=" & $sTo) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Return $sRead EndFunc I love when you fucking do that girl Cheers everyone https://iblockify.wordpress.com/ Link to comment Share on other sites More sharing options...
MHz Posted October 22, 2014 Share Posted October 22, 2014 I do like the alternative that trancexx provided. It does highlight the importance of a http user agent string that can be recognized. InetRead seems to be adequate with this example: expandcollapse popup; Set http user agent. $sUserAgent = _HttpSetUserAgent() ; Show http user agent being used MsgBox(0, 'Http User Agent', $sUserAgent) ; Get binary data from this URL. 9 = Force reload with binary mode. $URL = "http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el" $dData = InetRead($URL, 9) ; Convert the binary to a string. 4 = UTF8. $sData = BinaryToString($dData, 4) ; Show the UTF8 string. MsgBox(0, $URL, $sData) Func _HttpSetUserAgent($sPreferredUserAgent = 'Mozilla/5.0', $bForcePreference = False) ; Set http user agent. Local $sUserAgent If Not $bForcePreference Then ; Places of reading the http user agent can vary. This is just one place. $sUserAgent = RegRead('HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings', 'User Agent') EndIf If $sUserAgent == '' Then Switch $sPreferredUserAgent Case Default, 'Mozilla/5.0' $sUserAgent = 'Mozilla/5.0' Case '' $sUserAgent = '' Case Else $sUserAgent = $sPreferredUserAgent EndSwitch EndIf HttpSetUserAgent($sUserAgent) Return SetError(@error, @extended, $sUserAgent) EndFunc ; http://msdn.microsoft.com/en-us/library/ms537503%28v=vs.85%29.aspx ; Quote: ; "Note The user-agent string should not be used to indicate the presence of optional software or features. ; Custom version vectors, which can be detected using conditional comments, provide a more appropriate mechanism." ; ; http://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx ; Quote: ; "As with previous versions of Internet Explorer, portions of the user-agent string can vary according ; to the device running Internet Explorer, the operating system, and the environment." ; I doubt too many http servers will be looking for the http user agent string of "AutoIt" so IMO change it. Trident usually uses "Mozilla/4.0" or "Mozilla/5.0" with a possible features string appended. Output I get from testing: --------------------------- Http User Agent --------------------------- Mozilla/4.0 (compatible; MSIE 8.0; Win32) --------------------------- OK --------------------------- --------------------------- http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el --------------------------- [[["πατρίδα","hometown","patrída",""]],,"en",,[["πατρίδα",[1],true,false,572,0,1,0]],[["hometown",1,[["πατρίδα",572,true,false],["γενέτειρά",276,true,false],["hometown",128,true,false],["πόλη",13,true,false],["την πατρίδα",8,true,false]],[[0,8]],"hometown"]],,,[["en"]],3] --------------------------- OK --------------------------- Gianni and trancexx 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now