用的是Jsoup
static public void parsePage(Document doc) throws Exception {
List<Product> list = new ArrayList<Product>();
Elements productview = doc.select("div.tb-content");
Elements productgrids = productview.first().select("div.st-itembox");
for (Element productdiv : productgrids) {
Elements titlediv = productdiv.select(".summary");
Elements titlea = titlediv.select("a");
String name = titlea.first().attr("title");
String href = titlea.first().attr("href");
int sot = href.indexOf("."); // tmall 13 tao 15
int ids = href.indexOf("id");
long id = Long.parseLong(href.substring(ids+3,ids+12));
String freeposts = productdiv.select(".row-focus").toString();
int freepost;
if (freeposts.indexOf("icon-service-free") != -1) {
freepost = 1;
} else {
freepost = 0;
}
String storename = productdiv.select(".seller").text();
String payinfo = productdiv.select(".dealing").text();
int paycount = Integer.parseInt(payinfo.substring(0, payinfo.length() - 3));
String loc = productdiv.select(".loc").text();
String sprice = productdiv.select(".price").text();
float price = Float.parseFloat(sprice.substring(1, sprice.lastIndexOf(".")+2));
Product product = new Product();
product.setFreepost(freepost);
product.setLink(href);
product.setName(name);
product.setP_id(id);
product.setPaycount(paycount);
product.setPrice(price);
product.setStoreloc(loc);
product.setStorename(storename);
if (sot == 13)
product.setWeb("tianmao");
else if (sot == 11)
product.setWeb("taobao");
list.add(product);
}
insertDB(list);
}