java正则
2013-06-07 10:11 来源:www.chinab4c.com 作者:admin
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
import java.sql.*;
import java.net.URL;
public class rf {
public static void main(String[] args) {
//int x =getrf("http://www.digikey.cn/product-detail/zh/LTD-4708JS/160-1535-5-ND/408208");
//int x = getrf("http://www.digikey.cn//product-detail/zh/006/006-ND/2781733");
//System.out.println(x);
int x = 2;
String href;
int goods_id;
String sql;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://172.168.16.23:3306/icmall", "root","123456");
Statement st1 = con.createStatement();
Statement st2 = con.createStatement();
ResultSet rs = st1.executeQuery("select goods_id ,digikey_url from ecs_goods where s=0 limit 0,20000");
while(rs.next()){
href = "http://www.digikey.cn"+rs.getString("digikey_url");
//href = "http://www.digikey.cn//product-detail/zh/NJM2594V-TE1/NJM2594V-TE1TR-ND/638888";
//href = "http://www.digikey.cn//product-detail/zh/NJM2594V-TE1/NJM2594V-TE1TR-ND/638888";
//System.out.println(href);
if (href.length()>0) {
x = getrf(href);
//System.out.println(x);
goods_id = rs.getInt("goods_id");
if (x == 1) {//符合
sql = "update ecs_goods set is_rohs=1 ,s=1 where goods_id='"+goods_id+"'";
} else if (x == 2) {//不符合
sql = "update ecs_goods set s=1 where goods_id='"+goods_id+"'";
} else { //
sql = "update ecs_goods set is_rohs=2 ,s=1 where goods_id='"+goods_id+"'";
}
//System.out.println(sql);
st2.executeUpdate(sql);
}
}
System.out.println("采集完毕");
} catch(Exception e) {
//e.printStackTrace();
}
}
public static int getrf(String href){
int isrf = 2;
String temp;
StringBuffer br = new StringBuffer();
try {
URL url = new URL(href);
InputStreamReader ipt= new InputStreamReader(url.openStream(),"utf-8");
BufferedReader bf= new BufferedReader(ipt);
while((temp=bf.readLine())!=null) {
br.append(temp);
}
//System.out.println(br.toString());
//不符合限制有害物质指令
//Pattern p = Pattern.compile("\\s*不符合限制有害物");
//Matcher m = p.matcher(br.toString());符合限制有害物质指令
int x = (br.toString()).indexOf("不符合限制有害物");
//System.out.println(x);
if (x>0) {
return 2; //不符合
} else {
x = (br.toString()).indexOf("尚未确定供货商");
if (x > 0) {
return 3;
} else {
return 1;
}
}
//while(m.find()){
// System.out.println(m.group(1));
//}
} catch(Exception e){
//e.printStackTrace();
}
return isrf;
}
}
最近更新
常用插件
- ecshop分类树中统计商品数
最近忙于开发其他项目,在不少朋友不断要求和催促的情况下,做出了该小...
- ecshop红包修改成满多少减
我们在长期使用ecshop的时候,我们可以发现。ecshop的红包是一个非常强...
- ecshop通用红包编码
很多时候,为了结合促销,必须扩展一下ecshop的红包功能。ecshop的红包...
- ecshop降价通知登记插件
ecshop降价通知登记插件,主要是为了方便某些客户,对商品价格要求比...
- ecshop购物车功能改进[插件
ecshop购物车功能改进[插件套餐]主要是我们最近开发工作和开发项目中。...