init commit, get scores from html by loop
This commit is contained in:
commit
be14bf06c3
117
.gitignore
vendored
Normal file
117
.gitignore
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
|
||||
# Created by https://www.gitignore.io/api/java,intellij+all
|
||||
# Edit at https://www.gitignore.io/?templates=java,intellij+all
|
||||
|
||||
### Intellij+all ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
# JetBrains templates
|
||||
**___jb_tmp___
|
||||
|
||||
### Intellij+all Patch ###
|
||||
# Ignores the whole .idea folder and all .iml files
|
||||
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
|
||||
|
||||
.idea/
|
||||
|
||||
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
|
||||
|
||||
*.iml
|
||||
modules.xml
|
||||
.idea/misc.xml
|
||||
*.ipr
|
||||
|
||||
# Sonarlint plugin
|
||||
.idea/sonarlint
|
||||
|
||||
### Java ###
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# End of https://www.gitignore.io/api/java,intellij+all
|
85
src/Main.java
Normal file
85
src/Main.java
Normal file
@ -0,0 +1,85 @@
|
||||
import entities.Score;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
private static List<Score> scoreList = new ArrayList<>();
|
||||
|
||||
private static List<Score> getScoresByItemId(int itemId) {
|
||||
try {
|
||||
Document doc = Jsoup.connect("https://www.ceneo.pl/" + itemId).get();
|
||||
|
||||
getScoresFromPage(doc);
|
||||
|
||||
|
||||
System.out.println("\n\n");
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Object getTextFromElement(Element element, String cssQuery) {
|
||||
try {
|
||||
return element.selectFirst(cssQuery).text();
|
||||
} catch (NullPointerException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static void getScoresFromPage(Document document) {
|
||||
|
||||
Elements products = document.select("li.review-box");
|
||||
for (Element product : products) {
|
||||
System.out.println(getTextFromElement(product, "span.review-score-count"));
|
||||
// System.out.println(product);
|
||||
// Element score = product.selectFirst("span.review-score-count");
|
||||
// try {
|
||||
// System.out.println("score: " + score.text());
|
||||
// } catch (NullPointerException e) {
|
||||
// }
|
||||
//
|
||||
// Element description = product.selectFirst("p.product-review-body");
|
||||
// try {
|
||||
// System.out.println("description: \n" + description.text());
|
||||
// } catch (NullPointerException e) {
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// Element advElement = product.selectFirst("div.pros-cell");
|
||||
// Elements advCounter = advElement.select("li");
|
||||
// System.out.println("adv: " + advCounter.size());
|
||||
// } catch (NullPointerException e) {
|
||||
// System.out.println("adv: 0");
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// Element dissadvElement = product.selectFirst("div.cons-cell");
|
||||
// Elements dissadvCounter = dissadvElement.select("li");
|
||||
// System.out.println("adv: " + dissadvCounter.size());
|
||||
// } catch (NullPointerException e) {
|
||||
// System.out.println("dissadv: 0");
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
int[] productList = new int[]{29362313, 44279952};
|
||||
for (Integer item : productList) {
|
||||
getScoresByItemId(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
40
src/entities/Score.java
Normal file
40
src/entities/Score.java
Normal file
@ -0,0 +1,40 @@
|
||||
package entities;
|
||||
|
||||
public class Score {
|
||||
private float score;
|
||||
private String description;
|
||||
private int advantagesCounter;
|
||||
private int dissadvantagesCounter;
|
||||
|
||||
public float getScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
public void setScore(float score) {
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getAdvantagesCounter() {
|
||||
return advantagesCounter;
|
||||
}
|
||||
|
||||
public void setAdvantagesCounter(int advantagesCounter) {
|
||||
this.advantagesCounter = advantagesCounter;
|
||||
}
|
||||
|
||||
public int getDissadvantagesCounter() {
|
||||
return dissadvantagesCounter;
|
||||
}
|
||||
|
||||
public void setDissadvantagesCounter(int dissadvantagesCounter) {
|
||||
this.dissadvantagesCounter = dissadvantagesCounter;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user