- 浏览: 16868 次
- 性别:
- 来自: 广州
最新评论
Remark: set userAgent
package wisers.backend.worker; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URI; import java.net.URL; import java.net.URLConnection; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; public class HttpClient { public static void main(String args[]) throws IOException { try { //String content = executeGet("http://www.weibo.com/u/3097961187?is_hot=1"); //String content = executeGet("http://www.weibo.com/u/5935491442?is_hot=1"); String content = executeGet("http://www.etnet.com.hk/www/tc/stocks/realtime/quote_transaction.php?code=1816"); String locationStr = ""; if(content.indexOf("item_text W_fl")!=-1){ String [] contentArray = content.split("item_text W_fl"); locationStr = contentArray[2]; locationStr = locationStr.substring(locationStr.indexOf("\\t\\t\\t\\t\\t\\t\\t")+14, locationStr.indexOf("\\t\\t\\t\\t\\t\\t\\t")+20); } System.out.println(locationStr); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String executeGet(String url) throws Exception { BufferedReader in = null; String content = null; try { DefaultHttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(); request.addHeader("Connection","keep-alive"); request.addHeader("Cookie","__gads=ID=b3388a5add3ed972:T=1462503670:S=ALNI_Masqpbt9pk72seQaUUB-EvPqWd4Zw; BIGipServerWebHttpPool=236242954.20480.0000; PHPSESSID=b2a0753ed92cca53ec04f1a5ac27f4f1; et_rs_stk=1%7C1816; _gat=1; __AF=3fd36dc1-c366-4cfe-a286-858b92654fab; et_m_sid=b2a0753ed92cca53ec04f1a5ac27f4f1; et_color=2%3Blight; et_visitor=b2a0753ed92cca53ec04f1a5ac27f4f1; _ga=GA1.3.1021747879.1462503669; __asc=c0bd25171555706ce8f38bfbf60; __auc=19cbc18f15484030b93141bd4cd"); request.addHeader("Upgrade-Insecure-Requests","1"); request.addHeader("Host","www.etnet.com.hk"); request.addHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36"); request.setURI(new URI(url)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity() .getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); content = sb.toString(); System.out.println(content); } finally { if (in != null) { try { in.close(); } catch (Exception e) { e.printStackTrace(); } } return content; } } public static String sendGet(String url) { String result = ""; BufferedReader in = null; try { String urlName = url; //System.out.println(urlName); URL realUrl = new URL(urlName); URLConnection conn = realUrl.openConnection(); conn.setRequestProperty("accept", "*/*"); conn.setRequestProperty("connection", "Keep-Alive"); conn.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"); conn.connect(); in = new BufferedReader( new InputStreamReader(conn.getInputStream(),"utf-8")); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("����GET��������쳣��" + e); e.printStackTrace(); }finally { try { if (in != null) { in.close(); } } catch (IOException ex) { ex.printStackTrace(); } } return result; } }
发表评论
-
Maven install problem: Unexpected end of ZLIB input stream。
2018-03-08 12:58 596Maven install problem: Unexpect ... -
Call a java class from
2018-03-07 15:40 222中華人民共和國 -
Image Process
2017-10-31 09:08 161<div class="iteye-blog- ... -
mysql 存入 blob类型数据
2016-09-30 14:25 938String content = new String(bl ... -
java send email
2016-08-08 00:47 277static int port = 25; //smt ... -
phantomjs & casperjs install in l Fedora
2016-08-06 22:33 286phantomjs install in Fedora: ... -
Json String to Bean
2016-08-03 18:10 259<div class="iteye-blog- ... -
Java Read Html
2016-07-28 14:37 326Need Jar: jsoup-1.8.1.jar ... -
HttpClient Call Website
2016-07-28 14:14 342Need Jar: htmlunit-2.17-OSGi.j ... -
Java to Excel 2
2016-07-26 14:04 302Use Jar: poi-3.14-20160307.jar ... -
show process in mysql
2016-07-22 11:55 296SELECT * FROM INFORMATION_SCHEM ... -
Java to Excel
2016-07-15 16:14 268Java to Excel https://poi.apach ... -
Hibernate3 dynamicUpdate
2016-06-22 10:07 259@org.hibernate.annotations.Ent ... -
解決多線程派任務問題
2016-01-08 18:06 367解決多線程派任務問題: 使用: 每次只update 一條 ... -
daysBetween
2015-12-23 09:27 229public int daysBetween(Strin ... -
IntelliJ Idea – How to enable zoom of text by CTRL + Mouse wheel
2015-11-22 17:53 473IntelliJ Idea – How to ... -
List do sorting
2015-11-20 09:51 281Collections.sort(newList,new ... -
select multi tables join ---Hibernate
2015-10-29 14:05 601String hql = "from A a,B ... -
css 控制第二行字段縮進
2015-09-22 11:55 1155<div style="margin-left ... -
Hibernate: lazy load.
2015-08-05 12:27 370About lazy load, before you to ...
相关推荐
HttpClient httpClient = new HttpClient(); // 设置 Http 连接超时为5秒 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); /* 2 生成 GetMethod 对象并设置参数 */ GetMethod ...
赠送jar包:httpclient-4.5.6.jar; 赠送原API文档:httpclient-4.5.6-javadoc.jar; 赠送源代码:httpclient-4.5.6-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.6.pom; 包含翻译后的API文档:httpclient...
使用HttpClient发送请求、接收响应很简单,一般需要如下几步即可。 1. 创建HttpClient对象。 2. 创建请求方法的实例,并指定请求URL。如果需要发送GET请求,创建HttpGet对象;如果需要发送POST请求,创建...
赠送jar包:httpclient-4.5.13.jar; 赠送原API文档:httpclient-4.5.13-javadoc.jar; 赠送源代码:httpclient-4.5.13-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.13.pom; 包含翻译后的API文档:...
赠送jar包:httpclient-4.5.5.jar; 赠送原API文档:httpclient-4.5.5-javadoc.jar; 赠送源代码:httpclient-4.5.5-sources.jar; 包含翻译后的API文档:httpclient-4.5.5-javadoc-API文档-中文(简体)版.zip ...
赠送jar包:httpclient-4.5.13.jar; 赠送原API文档:httpclient-4.5.13-javadoc.jar; 赠送源代码:httpclient-4.5.13-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.13.pom; 包含翻译后的API文档:...
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods....
httpclient-4.5所需jar包,里面包含httpclient-4.5.jar等等10个必须的开发包。 1.commons-codec-1.9.jar 2.commons-logging-1.2.jar 3.fluent-hc-4.5.jar 4.httpclient-4.5.jar 5.httpclient-cache-4.5.jar 6....
HttpClient 4.5.3 (GA) is a maintenance release that fixes a number of defects found since 4.5.2. Please note that as of 4.4 HttpClient requires Java 1.6 or newer. Changelog: ------------------- * ...
httpclient.jar下载 包括code.jar包
try(CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(url); StringEntity stringEntity = new StringEntity(params, Charset.forName("UTF-8")); ...
Android使用HttpClient发送请求、接收响应很简单,只要如下几步即可: Step1:创建HttpClient对象; Step2:如果需要发送GET请求,则创建HttpGet对象; 如果需要发送POST请求,则创建HttpPost对象; Step3:如果...
赠送jar包:httpclient-4.2.5.jar; 赠送原API文档:httpclient-4.2.5-javadoc.jar; 赠送源代码:httpclient-4.2.5-sources.jar; 赠送Maven依赖信息文件:httpclient-4.2.5.pom; 包含翻译后的API文档:httpclient...
赠送jar包:httpclient-4.5.10.jar; 赠送原API文档:httpclient-4.5.10-javadoc.jar; 赠送源代码:httpclient-4.5.10-sources.jar; 赠送Maven依赖信息文件:httpclient-4.5.10.pom; 包含翻译后的API文档:...
压缩包中含有多个文档,从了解httpclient到应用。 httpClient 1httpClint 1.1简介 HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持...
赠送jar包:httpclient-4.5.2.jar; 赠送原API文档:httpclient-4.5.2-javadoc.jar; 赠送源代码:httpclient-4.5.2-sources.jar; 包含翻译后的API文档:httpclient-4.5.2-javadoc-API文档-中文(简体)版.zip ...
赠送jar包:httpclient-4.4.jar; 赠送原API文档:httpclient-4.4-javadoc.jar; 赠送源代码:httpclient-4.4-sources.jar; 赠送Maven依赖信息文件:httpclient-4.4.pom; 包含翻译后的API文档:httpclient-4.4-...
帮助程序员快速从Apache的HttpClient 3.x升级到HttpClient 4.x
赠送jar包:httpclient-4.5.3.jar 赠送原API文档:httpclient-4.5.3-javadoc.jar 赠送源代码:httpclient-4.5.3-sources.jar 包含翻译后的API文档:httpclient-4.5.3-javadoc-API文档-中文(简体)版.zip 对应Maven...