`

httpclient

阅读更多
package com.teamdev.jxbrowser.chromium.demo_lingshui.baidunuomi.shop;

import java.awt.BorderLayout;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;

import javax.swing.JFrame;
import javax.swing.WindowConstants;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.hyjx.common.CommonUtil;
import com.hyjx.orclJdbcUtil.JDBCUtils;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserPreferences;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.LoggerProvider;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
/**
* 百度糯米抓 评论总数 (COMM_TOTAL ) 差评数 (NEGATIVE_NUM) 店铺
*
*/
public class ls_bdnm_shop{
public static void main(String[] args) throws Exception {

    java.sql.Connection conOrcale  = null;
try {
conOrcale =    JDBCUtils.getConnection();
} catch (SQLException e1) {
e1.printStackTrace();
}
String sql = null;
PreparedStatement ps = null;
String  sql1 = null;
String  sql2 = null;
Statement st2 = null;
ResultSet rs2 = null;

Document doc = null;
try{
    sql1 = " select * from ls_nm_shop_good t  where t.plat_name ='百度糯米' and state is null ";
    sql2 = "update  ls_nm_shop_good set state = 'shop' , shop_url =? where good_url = ? ";
    st2  = (java.sql.Statement) conOrcale.createStatement();
rs2  = st2.executeQuery(sql1);
ps = conOrcale.prepareStatement(sql2);
}catch (Exception e) {
e.printStackTrace();
}
int i = 1;
String gurl="";
for(;rs2.next();){
try {
Thread.sleep(1000);
} catch (Exception e) {
// TODO: handle exception
}
System.out.println(i);
i++;
final  String good_url = rs2.getString("good_url");
   String good_type = rs2.getString("good_type");
try {
gurl= search(good_url,good_type);
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("该商品已经下线或者该店铺没有url");
continue;
}
//修改状态
ps.setString(1,gurl);
ps.setString(2,good_url);
    ps.executeUpdate();
}

       
}

static String search(final String good_url ,String good_type)throws Exception{
System.out.println("url========="+good_url);
java.sql.Connection conOrcale2  = null;
try {
conOrcale2 =    JDBCUtils.getConnection();
} catch (SQLException e1) {
e1.printStackTrace();
}
String sql = null;
PreparedStatement ps = null;
try{
sql = "insert into ls_nm_shop   "+
"  (shop_id, site_ent_id, platform_code,shop_name,shop_address,shop_url,tellphone,type)  "+
"  values " +
"( ?   ,  ? ,   ?   ,  ?,  ? ,  ?,  ?,?)  ";
    ps = conOrcale2.prepareStatement(sql);
}catch (Exception e) {
e.printStackTrace();
}

Document doc = null;
String text ="";
//httpclient
CloseableHttpClient httpclient = HttpClients.createDefault(); 
HttpGet httpget = new HttpGet(good_url);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String ahtml = EntityUtils.toString(entity, "UTF-8");
httpget.releaseConnection();


String deal_id="";
if(ahtml.contains("article")){
deal_id=ahtml.substring(ahtml.indexOf("article")+8,ahtml.indexOf("section"));
// F.context("goods_id", "31217598");
deal_id=deal_id.substring(deal_id.lastIndexOf("=")+1,deal_id.length()-5);
}
if(ahtml.contains("goods_id")&&deal_id ==null){
deal_id=ahtml.substring(ahtml.indexOf("goods_id")+8,ahtml.indexOf("merchant_ids"));
// F.context("goods_id", "31217598");
deal_id=deal_id.substring(deal_id.lastIndexOf(",")+3);
deal_id=deal_id.substring(0,deal_id.lastIndexOf(")")-1);
}

System.out.println("deal_id="+deal_id);
System.out.println("https://www.nuomi.com/pcindex/main/shopchain?dealId="+deal_id);
//详细
doc = Jsoup.connect("https://www.nuomi.com/pcindex/main/shopchain?dealId="+deal_id).userAgent("Mozilla")
.header("method", "GET")
.header("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.header("Accept-Encoding:","gzip, deflate, sdch")
.header("Accept-Language","zh-CN,zh;q=0.8")
.header("Cache-Control","max-age=0")
.header("Connection","keep-alive")
.header("Host","lingshui.nuomi.com")
.header("Upgrade-Insecure-Requests","1")
.header("User-Agent","Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36")
.ignoreContentType(true).timeout(200000).data()
.get();
//获取json
text = doc.text();
System.out.println(text);
JSONObject ojson = new JSONObject(text);
    // JSONArray ajson = (JSONArray) ojson.get("data");
     JSONObject oojson=(JSONObject) ojson.get("data");
    
     String shop_name=(String) oojson.get("name");
     String shop_url="https:"+(String) ((JSONObject) ((JSONArray) oojson.get("shop")).get(0)).get("link");
     String shop_address=(String) ((JSONObject) ((JSONArray) oojson.get("shop")).get(0)).get("address");
    
     String tellphone=(String) ((JSONObject) ((JSONArray) oojson.get("shop")).get(0)).get("phone");//电话号码
    
System.out.println("店铺名称="+shop_name);
System.out.println("shop_url="+shop_url);
System.out.println("店铺地址 ="+shop_address);
System.out.println("电话="+tellphone);
   
try {
//(shop_id, site_ent_id, platform_code,shop_name,shop_address,shop_url,tellphone,type)
             ps.setString(1,CommonUtil.getUUID32());
ps.setString(2,CommonUtil.getUUID32());
ps.setString(3,"010");
ps.setString(4,shop_name);
ps.setString(5,shop_address);
ps.setString(6,shop_url);
ps.setString(7,tellphone);
ps.setString(8,good_type);
ps.executeUpdate();


} catch (Exception e1) {
// TODO Auto-generated catch block

}
conOrcale2.close();
        System.out.println("---------------------------------------------------------------------------------------------");
        if(shop_url.length()>0){
        return shop_url;
        }
        return null;
       
}



}
分享到:
评论

相关推荐

    httpClient

    HttpClient httpClient = new HttpClient(); // 设置 Http 连接超时为5秒 httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000); /* 2 生成 GetMethod 对象并设置参数 */ GetMethod ...

    httpclient-4.5.6-API文档-中文版.zip

    赠送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-4.5.13-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文档:...

    httpclient-4.5.5-API文档-中文版.zip

    赠送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 ...

    httpclient-4.5.13-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文档:...

    可用org.apache.commons.httpclient-3.1.0.jar.zip

    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.5jar

    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....

    httpclient4.5.3 jar完整包含所有依赖包

    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包下载

    httpclient.jar下载 包括code.jar包

    SpringBoot使用httpclient发送Post请求时

    try(CloseableHttpClient httpClient = HttpClients.createDefault()) { HttpPost httpPost = new HttpPost(url); StringEntity stringEntity = new StringEntity(params, Charset.forName("UTF-8")); ...

    Android_HttpClient_jar包

    Android使用HttpClient发送请求、接收响应很简单,只要如下几步即可: Step1:创建HttpClient对象; Step2:如果需要发送GET请求,则创建HttpGet对象; 如果需要发送POST请求,则创建HttpPost对象; Step3:如果...

    httpclient-4.2.5-API文档-中文版.zip

    赠送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...

    httpclient-4.5.10-API文档-中文版.zip

    赠送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到应用。 httpClient 1httpClint 1.1简介 HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持...

    httpclient-4.5.2-API文档-中文版.zip

    赠送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 ...

    httpclient-4.4-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-...

    HttpClient 3.x to HttpComponents HttpClient 4.x

    帮助程序员快速从Apache的HttpClient 3.x升级到HttpClient 4.x

    httpclient-4.5.3-API文档-中文版.zip

    赠送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...

Global site tag (gtag.js) - Google Analytics