Я пытаюсь войти в yahoo.de с помощью htpclient.но я не могу этого сделать.Из вывода я вижу, что он требует обработки JavaScript.Кто-нибудь знает, как мне это сделать?Вот код и вывод моей программы. Я был бы очень признателен за любую помощь. Спасибо.
import java.io.DataOutputStream;импорт java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;
import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.HttpStatus;import org.apache.commons.httpclient.NameValuePair;import org.apache.commons.httpclient.cookie.CookiePolicy;import org.apache.commons.httpclient.methods.GetMethod;import org.apache.commons.httpclient.methods.PostMethod;import org.apache.commons.httpclient.params.HttpMethodParams;import org.apache.http.Header;import org.htmlparser.Node;import org.htmlparser.NodeFilter;import org.htmlparser.Parser;import org.htmlparser.filters.TagNameFilter;import org.htmlparser.util.NodeList;import org.htmlparser.util.ParserException;
открытый класс YahooParser {HttpClient client = new HttpClient ();статический NodeFilter inputfilter = new TagNameFilter ("input");статический NodeFilter linkfilter = new TagNameFilter ("a");void parser_getemails (String website_url, String emailID, String password) выдает HttpException, IOException, ParserException {String url_post = null;client.getParams (). setParameter (HttpMethodParams.USER_AGENT, "Mozilla / 5.0 (Windows; U; Windows NT 6.1; en-US; rv: 1.9.2.3) Gecko / 20100401 Firefox / 3.6.3 (.NET CLR 3.5.30729) ");
GetMethod get_siteurl = new GetMethod(website_url);
//get_siteurl.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
client.executeMethod(get_siteurl);
String output_get=get_siteurl.getResponseBodyAsString();
//System.out.println(get_siteurl.getResponseBodyAsString());
get_siteurl.releaseConnection();
Parser parser= new Parser(output_get);
NodeList nodelist1 = parser.parse(null);
NodeList list1 = nodelist1.extractAllNodesThatMatch(inputfilter , true);
String u=list1.elementAt(10).getText();
String challenge=list1.elementAt(12).getText();
//System.out.println("u is "+u); System.out.println("chllange is: "+challenge);
String s[]=u.split("\""); u=s[5];
String s1[]=challenge.split("\"");challenge=s1[5];
PostMethod post_uname_pwd = new PostMethod("https://login.yahoo.com/config/login?");
post_uname_pwd.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
NameValuePair userid = new NameValuePair("login","emailid@yahoo.de");
NameValuePair pwd = new NameValuePair("passwd", "password");
NameValuePair tries = new NameValuePair(".tries", "1");
NameValuePair src = new NameValuePair(".src", "ym");
NameValuePair md5 = new NameValuePair(".md5", "");
NameValuePair hash = new NameValuePair(".hash", "");
NameValuePair js = new NameValuePair(".js", "");
NameValuePair last = new NameValuePair(".last", "");
NameValuePair promo = new NameValuePair("promo", "");
NameValuePair intl = new NameValuePair(".intl", "de");
NameValuePair bypass = new NameValuePair(".bypass", "");
NameValuePair partner = new NameValuePair(".partner", "");
NameValuePair u1 = new NameValuePair(".u", u);
NameValuePair v = new NameValuePair(".v", "0");
NameValuePair challenge1 = new NameValuePair(".challenge", challenge);
NameValuePair yplus = new NameValuePair(".yplus", "");
NameValuePair emailcode = new NameValuePair(".emailCode", "");
NameValuePair pkg = new NameValuePair("pkg", "c");
NameValuePair stepid = new NameValuePair("stepid", "");
NameValuePair ev = new NameValuePair(".ev", "");
NameValuePair hasmsgr = new NameValuePair("hasMsgr", "0");
NameValuePair chkp = new NameValuePair(".chkP", "Y");
NameValuePair done= new NameValuePair(".done", "http://mail.yahoo.com");
NameValuePair pd = new NameValuePair(".pd", "ym_ver=0&c=&ivt=&sg=");
NameValuePair[] data = {userid,pwd,tries,src,md5,hash,js,last,promo,intl,bypass,partner,u1,v,challenge1,yplus,emailcode,pkg,stepid,ev,hasmsgr,chkp,done,pd};
post_uname_pwd.getParams().setCookiePolicy(org.apache.http.client.params.CookiePolicy.BROWSER_COMPATIBILITY);
post_uname_pwd.setRequestBody(data);
post_uname_pwd.setRequestHeader("user-agent", "Mozilla/5.0 (Macintosh; U; PPCMac OS X; en-us) AppleWebKit/124 (KHTML, like Gecko) Safari/125.1");
post_uname_pwd.addRequestHeader("Accept", "*/*");
post_uname_pwd.addRequestHeader("Accept-Language", "en-us, ja;q=0.21,de-de;q=0.86, de;q=0.79, fr-fr;q=0.71, fr;q=0.64, nl-nl;q=0.57,nl;q=0.50, it-it;q=0.43, it;q=0.36, ja-jp;q=0.29, en;q=0.93,es-es;q=0.14, es;q=0.07");
client.executeMethod(post_uname_pwd);
String post_op=post_uname_pwd.getResponseBodyAsString();
System.out.println(post_op);
int statuscode = post_uname_pwd.getStatusCode();
System.out.println(statuscode);
post_uname_pwd.releaseConnection();
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT))
{
Header header = (Header) post_uname_pwd.getResponseHeader("Location");
if (header != null)
{
url_post = header.getValue();
System.out.println(url_post);
GetMethod redirect = new GetMethod(url_post);
client.executeMethod(redirect);
String output =redirect.getResponseBodyAsString();
//System.out.println(output);
if(output != null)
{
//System.out.println(output);
FileOutputStream fos = new FileOutputStream("C:\\Documents and Settings\\patel\\My Documents\\yahoo.html");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeBytes(output);
File file = new File("C:\\Documents and Settings\\patel\\My Documents\\yahoo.html");
FileInputStream fis = new FileInputStream(file);
}
redirect.releaseConnection();
}
}
}
}
output:
Если вы видите эту страницу, настройки вашего браузера не позволяют автоматически перенаправлять нановый URL.
Пожалуйста, нажмите здесь , чтобы продолжить.