YasserKhalil
Well-Known Member
Hello everyone
The following code translates from column A from Arabic to English based on google translate.
The code is working but after a while the IP is blocked .. How can I use Proxies in this code so as to prevent the IP block?
The following code translates from column A from Arabic to English based on google translate.
Code:
Sub Test()
Dim b As Boolean, lngFrom As String, lngTo As String, strText As String, strURL As String, strResponse As String, i As Long
lngFrom = "ar"
lngTo = "en"
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Not IsEmpty(Cells(i, 1)) Then
strText = Application.EncodeURL(Range("A" & i).Value)
strURL = "https://translate.google.com/translate_a/t?client=s&text={S}&hl=en&sl={F}&tl={T}&multires=1&pc=0&rom=1&sc=1"
strURL = Replace$(strURL, "{S}", strText)
strURL = Replace$(strURL, "{F}", lngFrom)
strURL = Replace$(strURL, "{T}", lngTo)
strResponse = sendGETRequest(strURL)
If InStr(strResponse, "Sometimes you may see this page if you are using advanced terms that robots") Then GoTo Skipper
Range("B" & i).Value = Replace(strResponse, """", ""): b = True
Skipper:
If b = False Then Exit For
End If
Next i
If b Then MsgBox "Done...", vbInformation Else MsgBox "It Seems IP Blocked", vbExclamation
End Sub
Function sendGETRequest(URL As String) As String
Dim XMLHTTP As New MSXML2.XMLHTTP
XMLHTTP.Open "GET", URL, False
XMLHTTP.send ("")
sendGETRequest = XMLHTTP.responseText
End Function
The code is working but after a while the IP is blocked .. How can I use Proxies in this code so as to prevent the IP block?