selenium自动化网站识别验证码登录下载上传文件

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

packageweb;importjava.io.File;/***获取打包后jar的路径信息*@authorAdministrator*2011-01-1613:53:12*/publicclassJarTool{//获取jar绝对路径publicstaticStringgetJarPath(){Filefile=getFile();if(file==null)returnnull;returnfile.getAbsolutePath();}//获取jar目录publicstaticStringgetJarDir(){Filefile=getFile();if(file==null)returnnull;returngetFile().getParent();}//获取jar包名publicstaticStringgetJarName(){Filefile=getFile();if(file==null)returnnull;returngetFile().getName();}privatestaticFilegetFile(){//关键是这行...Stringpath=JarTool.class.getProtectionDomain().getCodeSource().getLocation().getFile();try{path=java.net.URLDecoder.decode(path,UTF-8);//转换处理中文及空格}catch(java.io.UnsupportedEncodingExceptione){returnnull;}returnnewFile(path);}}packageweb;importjava.io.BufferedReader;importjava.io.FileInputStream;importjava.io.IOException;importjava.io.InputStreamReader;importjava.util.ArrayList;importjava.util.Calendar;importjava.util.Collections;publicclasslastday{Stringlsday()throwsException{Calendarnow=Calendar.getInstance();Stringnyr=now.get(Calendar.YEAR)+lastday.plus(now.get(Calendar.MONTH)+1)+lastday.plus(now.get(Calendar.DAY_OF_MONTH));ArrayListStringlist_h=newArrayListString();BufferedReaderreader1=newBufferedReader(newInputStreamReader(newFileInputStream(JarTool.getJarDir()+/initdate.txt),gbk));Stringline1=null;while((line1=reader1.readLine())!=null){if(nyr.compareTo(line1)0){list_h.add(line1);}}//降序Collections.reverse(list_h);//不指定排序规则时,也是按照字母的来排序的return(list_h.get(0));}staticStringplus(inta){Stringcan1=a+;if(can1.length()2){Stringcan2=0+can1;returncan2;}else{Stringcan2=can1;returncan2;}}}packageweb;importjava.io.IOException;importjava.net.InetAddress;importjava.net.InetSocketAddress;importjava.net.Socket;importjava.net.SocketAddress;importjava.net.UnknownHostException;importjava.security.KeyManagementException;importjava.security.NoSuchAlgorithmException;importjava.security.cert.CertificateException;importjava.security.cert.X509Certificate;importjavax.net.SocketFactory;importjavax.net.ssl.SSLContext;importjavax.net.ssl.TrustManager;importjavax.net.ssl.X509TrustManager;importorg.apache.commons.httpclient.ConnectTimeoutException;importorg.apache.commons.httpclient.params.HttpConnectionParams;importorg.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;/***MySecureProtocolSocketFactory.java.javaCreateon2012-9-26下午1:15:03***Copyright(c)2012byMTA.**@authorlmeteor*@Emailtxin0814@sina.com*@description自定义的socketfactory实现自动接受证书*@version1.0*/publicclassMySecureProtocolSocketFactoryimplementsSecureProtocolSocketFactory{privateSSLContextsslcontext=null;privateSSLContextcreateSSLContext(){SSLContextsslcontext=null;try{sslcontext=SSLContext.getInstance(SSL);sslcontext.init(null,newTrustManager[]{newTrustAnyTrustManager()},newjava.security.SecureRandom());}catch(NoSuchAlgorithmExceptione){e.printStackTrace();}catch(KeyManagementExceptione){e.printStackTrace();}returnsslcontext;}privateSSLContextgetSSLContext(){if(this.sslcontext==null){this.sslcontext=createSSLContext();}returnthis.sslcontext;}publicSocketcreateSocket(Socketsocket,Stringhost,intport,booleanautoClose)throwsIOException,UnknownHostException{returngetSSLContext().getSocketFactory().createSocket(socket,host,port,autoClose);}publicSocketcreateSocket(Stringhost,intport)throwsIOException,UnknownHostException{returngetSSLContext().getSocketFactory().createSocket(host,port);}publicSocketcreateSocket(Stringhost,intport,InetAddressclientHost,intclientPort)throwsIOException,UnknownHostException{returngetSSLContext().getSocketFactory().createSocket(host,port,clientHost,clientPort);}publicSocketcreateSocket(Stringhost,intport,InetAddresslocalAddress,intlocalPort,HttpConnectionParamsparams)throwsIOException,UnknownHostException,ConnectTimeoutException{if(params==null){thrownewIllegalArgumentException(Parametersmaynotbenull);}inttimeout=params.getConnectionTimeout();SocketFactorysocketfactory=getSSLContext().getSocketFactory();if(timeout==0){returnsocketfactory.createSocket(host,port,localAddress,localPort);}else{Socketsocket=socketfactory.createSocket();SocketAddresslocaladdr=newInetSocketAddress(localAddress,localPort);SocketAddressremoteaddr=newInetSocketAddress(host,port);socket.bind(localaddr);socket.connect(remoteaddr,timeout);returnsocket;}}//自定义私有类privatestaticclassTrustAnyTrustManagerimplementsX509TrustManager{publicvoidcheckClientTrusted(X509Certificate[]chain,StringauthType)throwsCertificateException{}publicvoidcheckServerTrusted(X509Certificate[]chain,StringauthType)throwsCertificateException{}publicX509Certificate[]getAcceptedIssuers(){returnnewX509Certificate[]{};}}}packageweb;importjava.awt.Graphics;importjava.awt.Image;importjava.awt.image.BufferedImage;importjava.awt.image.ImageProducer;importjava.awt.image.MemoryImageSource;importjava.io.BufferedReader;importprocess.algorithms.Elements;importprocess.param.*;importprocess.common.Common;importjava.io.File;importjava.io.FileInputStream;importjava.io.InputStreamReader;importjava.util.ArrayList;importjava.util.List;publicc

1 / 43
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功