Em dùng chương trình c# truy vấn dữ liệu từ google. Truy vấn được khoảng 300 lần thì Server google chặn. Em đã thử đổi proxy nhưng không được.
Đoạn code lấy dữ liệu từ google và đổi proxy:
Kết quả trả về:
Mong các cao thủ giúp đỡ.
Đoạn code lấy dữ liệu từ google và đổi proxy:
Code:
string str; if (!string.IsNullOrEmpty(keyword)) { string url = "http://www.google.com.vn/search?num=1&q=" + keyword.Replace(" ", "+") + "&aq=f&aqi=&aql=f&ie=UTF-8&btnG=Search"; try { //string url = "http://www.google.com.vn/search?num=1&q=" + keyword.Replace(" ", "+") + "&aq=f&aqi=&aql=f&ie=UTF-8&btnG=Search"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.KeepAlive = false; request.UserAgent = "Mozilla/11.0"; request.Method = "GET"; request.ContentType = "text/html"; request.Timeout = 30000; if (!string.IsNullOrEmpty(strProxy) && int.Parse(strProxy.Split(':')[1]) != 0) { string address = strProxy.Split(':')[0]; int port = int.Parse(strProxy.Split(':')[1]); WebProxy myProxy = new WebProxy(address, port); myProxy.BypassProxyOnLocal = false; request.Proxy = myProxy; } //WebProxy myproxy = new WebProxy("31.172.30.3", 443); //myproxy.BypassProxyOnLocal = false; //request.Proxy = myproxy; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { str = reader.ReadToEnd(); } response.Close(); } catch (Exception e) { Console.WriteLine("Proxy:{0}\t{1}", strProxy, e.Message); strProxy = gIP.GetProxyFromHideMyAss(); // Ham lay proxy moi return -1; } }
Mong các cao thủ giúp đỡ.
Comment