Skip to content

Commit

Permalink
разобраться с формированием книги
Browse files Browse the repository at this point in the history
  • Loading branch information
svdvovan committed Jul 23, 2018
1 parent 6ac5c02 commit 59e359c
Showing 1 changed file with 91 additions and 88 deletions.
179 changes: 91 additions & 88 deletions src/TestTest/ecolasShop.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package TestTest;

import com.sun.xml.internal.bind.v2.TODO;
import org.apache.commons.io.FileUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
Expand All @@ -15,137 +16,139 @@

/**
* Created by SretenskyVD on 23.07.2018.
* keytool -import -v -file F:/Projects/TestCopy/cert/ecolashopru.crt -keystore F:/Projects/TestCopy/cert/ecolashopru.crt.jks -storepass drowssap
*/
public class ecolasShop {
public static void main(String[] args) throws IOException {


String NameHost = "https://www.bibihouse.ru";
Workbook wb = new HSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("1лист");

System.setProperty("javax.net.ssl.trustStore", "S:/ProjectJava/ecolasShop/cert/ecolashopruru.crt.jks");
String Path = "https://ecolashop.ru/lamps/?limit=10";

// System.setProperty("javax.net.ssl.trustStore", "S:/ProjectJava/ecolasShop/cert/ecolashopruru.crt.jks");
System.setProperty("javax.net.ssl.trustStore", "F:/Projects/TestCopy/cert/ecolashopru.crt.jks");
// String Path = "https://ecolashop.ru/lamps/?limit=500";
// String Path = "https://ecolashop.ru/lights/?limit=590";
String Path = "https://ecolashop.ru/lights/";


int Page = 1;

// int Page = 1;
for (int count = 0; count <= 5; count++) {
Path = "https://ecolashop.ru/lights/?page=" + Page;
Document doc1 = (Document) Jsoup.connect(Path).get();
Elements links1 = doc1.getElementsByClass("product-layout product-list col-xs-12");
String Category = doc1.getElementsByClass("title-category").select("h1").text();

// for (int count = 0; count <= 1; count++) {
// Path = "https://ecolashop.ru/lamps/?limit=10";
Document doc1 = (Document) Jsoup.connect(Path).get();
Elements links1 = doc1.getElementsByClass("product-layout product-list col-xs-12");

int y = 0;
for (Element link1 : links1) {
String addressUrl = (links1.get(y).select("a[href]").attr("abs:href"));
System.out.println(addressUrl);
int y = 0;
for (Element link1 : links1) {
String addressUrl = (links1.get(y).select("a[href]").attr("abs:href"));
System.out.println(addressUrl);

Document doc2 = Jsoup.connect(addressUrl).get();
Document doc2 = Jsoup.connect(addressUrl).get();

String Price = doc2.getElementsByClass("autocalc-product-price").text();
Elements Unit = doc2.getElementsByClass("characteristics-list__label");
Elements Value = doc2.getElementsByClass("characteristics-list__value");
Elements Image = doc2.getElementsByClass("preview");
String NameProduct = doc2.getElementsByClass("title-category").select("h1").text();
String Kod = doc2.getElementsByClass("list-unstyled product-view").select("span").text();
String Description = doc2.getElementsByClass("tab-pane active").text();
String Price = doc2.getElementsByClass("autocalc-product-price").text();
Elements Image = doc2.getElementsByClass("thumbnail");
String NameProduct5 = doc2.getElementsByClass("title-category").select("h1").text();
String Kod = doc2.getElementsByClass("list-unstyled product-view").select("span").text();
String Description = doc2.getElementsByClass("tab-pane active").text();

System.out.println(Category);


String NameProduct4 = NameProduct5.replace("/", "");
String NameProduct3 = NameProduct4.replace("\\", "");
String NameProduct2 = NameProduct3.replace("*", "x");
String NameProduct = NameProduct2.replace("\"", "");
System.out.println(NameProduct);

Row row = sheet.createRow(y);

System.out.println(NameProduct);
Cell cell = row.createCell(0);
cell.setCellValue(Kod);

Row row = sheet.createRow(y);
Cell cell1 = row.createCell(3);
cell1.setCellValue(NameProduct);

Cell cell = row.createCell(0);
cell.setCellValue(Kod);
System.out.println(Price);

Cell cell1 = row.createCell(3);
cell1.setCellValue(NameProduct);
//
// String NameProduct2 = NameProduct.replace("\"","");
// System.out.println(NameProduct2);
// String NameProduct3 = NameProduct2.replace("/","");
// System.out.println(NameProduct3);
// String NameProduct4 = NameProduct3.replace(" ","_");
// System.out.println(NameProduct4);
// String NameProduct5 = NameProduct4.replace(".","");
// System.out.println(NameProduct5);
System.out.println(Price);
Cell cell2 = row.createCell(4);
cell2.setCellValue(Price);

Cell cell2 = row.createCell(4);
cell2.setCellValue(Price);
Cell cell5 = row.createCell(5);
cell5.setCellValue(Description);

// Cell cell5 = row.createCell(5);
// cell2.setCellValue(Description);

Elements table = doc2.select("table");
// Elements row1 = table.select("tr");
Iterator<Element> ite = table.select("td").iterator();
Elements row2 = table.select("td");

int y2 = 8;
for (Element rows : row2) {

Elements table = doc2.select("table");
Elements row1 = table.select("tr");
Iterator<Element> ite = table.select("td").iterator();
// System.out.println(ite.next().text() + " ");
String Har = ite.next().text();
System.out.print(Har);
Cell cell10 = row.createCell(y2);
cell10.setCellValue(Har);
y2++;
}

for (Element rows : row1) {
System.out.println(ite.next().text() + " ");
System.out.print(ite.next().text() + "|");
}

int Img = 0;
int y3 = 27;
for (Element Images : Image) {
String FileName = Image.get(Img).select("img").attr("src");
System.out.println(FileName);

Cell cell11 = row.createCell(y3);
cell11.setCellValue(FileName);
y3++;

File f = new File(FileName);
// System.out.print(Image.get(Img).attr("src")+ ";");
// System.out.print("data/image/auto/1/" + f.getName() + ",");

int Attr=0;
for (Element Units: Unit) {
String Opis = Unit.get(Attr).text() + "|" + Value.get(Attr).text();
System.out.print(Unit.get(Attr).text() + "|" + Value.get(Attr).text() + "\n");

Attr++;
try {
//Копирование фото
String FILENAME = "F:/Projects/TestCopy/foto/" + Category + "/" + NameProduct + "/" + f.getName();
String SvDPDFURL = FileName;
File file = new File(FILENAME);

Cell cell3 = row.createCell(3);
cell3.setCellValue(Opis);
URL url = new URL(SvDPDFURL);
FileUtils.copyURLToFile(url, file);
} catch (java.io.FileNotFoundException e) {
System.out.println("не найден путь ");
}

}

int Img=0;
for (Element Images: Image) {
String FileName = Image.get(Img).attr("src");
System.out.println(NameHost+FileName);

File f = new File(FileName);
// System.out.print(Image.get(Img).attr("src")+ ";");
// System.out.print("data/image/auto/1/" + f.getName() + ",");
Img++;
}
System.out.println();

y++;
}

//try{
// //Копирование фото
// String FILENAME = "S:/ProjectJava/TestCopy/foto/"+NameProduct5+ "/" + f.getName();
// String SvDPDFURL = NameHost +FileName ;
// File file = new File(FILENAME);
//
// URL url = new URL(SvDPDFURL);
// FileUtils.copyURLToFile(url, file);}
//catch (java.io.FileNotFoundException e){
// System.out.println("не найден путь ");
//}
}

Page++;
try (OutputStream fileOut = new FileOutputStream(+Page+"book.xls")) {
wb.write(fileOut);

Img++;
}
System.out.println();

y++;
// }
// Page++;
}
try (OutputStream fileOut = new FileOutputStream("book.xls")){
wb.write(fileOut);}
catch (FileNotFoundException e) {
} catch(FileNotFoundException e){
e.printStackTrace();
} catch (IOException e) {
} catch(IOException e){
e.printStackTrace();

}

}

}
}



0 comments on commit 59e359c

Please sign in to comment.