[英]Handle popup's in httpclient
是否可以使用 apache http 客戶端處理彈出窗口?
我正在嘗試訪問該網站。 訪問特定頁面會彈出一個新窗口,在 http 響應中,我得到的都是 HTML 中的彈出新窗口代碼。
有沒有辦法從http客戶端重定向到新的彈出窗口?
我的代碼
HttpResponse res = null;
HttpEntity entity = null;
DefaultHttpClient defClient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("http://sudhaezine.com/svww_loginform.php?email=guest@xxx.com&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>
您無法使用 http 客戶端自動處理此類彈出窗口,因為它們是通過客戶端 JavaScript 代碼創建的。 所以你需要帶有 JS 解釋器的客戶端(比如 Web 瀏覽器)。
您可以通過對 JavaScript 代碼進行逆向工程,將您從響應正文中獲取的參數傳遞給結果函數,並使用 http 客戶端向生成的 url 發出新請求。 此過程稱為Web 抓取。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.