2013-07-22 45 views
0

是否可以使用apache http客戶端來處理彈出窗口?在httpclient中處理彈出窗口

我正在嘗試訪問該網站。訪問一個特定的頁面彈出一個新的窗口,並在http響應中,我彈出了HTML中的新窗口代碼。

有沒有辦法從http客戶端重定向到新的彈出窗口?

我的代碼

HttpResponse res = null; 
HttpEntity entity = null; 
DefaultHttpClient defClient = new DefaultHttpClient(); 

HttpPost httpost = new HttpPost("http://sudhaezine.com/[email protected]&password=yyy&brw=safari"); 
res = defClient.execute(httpost); 
entity = res.getEntity(); 

StringBuffer sb = new StringBuffer(); 
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); 
String str; 
while ((str = reader.readLine()) != null) { 
    sb.append(new String(str.getBytes(), "UTF-8")); 
} 
entity.consumeContent(); 

這給了下面的響應

<html><head> <title></title></head><META HTTP-EQUIV=refresh content=30;url=thankyou.php><body background="images/bg1.gif"><script language="javascript">var popupstr=''; //var bor = navigator.appName; //alert(bor); doPopUpWindow = window.open("svww_index1.php","StarView",'width=800,height=600,left=0,top=0'+popupstr); // if (!doPopUpWindow) {  //Popup blocked open with in current browser window.  // doPopUpWindow = window.open("svww_index1.php","_parent",'width='+ screen.availWidth +',height='+ screen.availHeight +',left=0,top=0'+popupstr); // } try{ var obj = doPopUpWindow.name; // window.close();//WindowOpen.close();//alert("Popup blocker NOT detected"); } catch(e){  doPopUpWindow = window.open("svww_index1.php","_parent",'width='+ screen.availWidth +',height='+ screen.availHeight +',left=0,top=0'+popupstr); }</script></body></html> 

回答

1

,因爲他們是通過客戶端的JavaScript代碼中創建您無法自動處理這樣的彈出窗口與HTTP客戶端。所以你需要JS解釋器(如Web瀏覽器)的客戶端。

您可以繼續進行反向工程JavaScript代碼,將您從響應主體獲取的參數傳遞給結果函數,並使用http客戶端向生成的url發出新請求。這個過程被稱爲Web scrapping