Compare commits

..

No commits in common. "feature/setup-debugging" and "master" have entirely different histories.

8 changed files with 5 additions and 145 deletions

6
.gitignore vendored
View File

@ -1,6 +1,2 @@
target/
.vscode/
tomcat-binaries/
src/main/amazon-scrapi/WEB-INF/classes/
src/main/amazon-scrapi/WEB-INF/lib/
.vscode/

View File

@ -1,29 +1,3 @@
# amazon-scrapi
An API interface with Amazon, that uses webscraping
# Development Resources
- [Intro to servlets](https://dev.to/dilanka-rathnasiri/introduction-to-java-servlets-32oc)
# Development Environment Setup
## VSCode / VSCodium
Install the following softwares
- Required for development
- Maven
- Java JDK
- Git
- Highly recommended for debugging or deployment
- [Apache Tomcat](https://tomcat.apache.org)
- Docker
VSCode Extensions
- Extension Pack for Java
### Tomcat
Download binaries for Tomcat.
You can get a VSCode extension to deploying project to Tomcat for debugging.
Following these guides.
- Extension Setup [(Video](https://www.youtube.com/watch?v=R9mugpHWr14) - [Article)](https://www.brandondonnelson.com/2020/06/debugging-java-web-app-in-visual-studio.html).
- Helped understand config [(video)](https://www.youtube.com/watch?v=RiPot1ne8rI)
An API interface with Amazon, that uses webscraping

20
pom.xml
View File

@ -28,21 +28,6 @@
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.playwright</groupId>
<artifactId>playwright</artifactId>
<version>1.48.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.5.12</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>1.5.12</version>
</dependency>
</dependencies>
<build>
@ -52,9 +37,8 @@
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<webappDirectory>src/main/amazon-scrapi</webappDirectory>
<webXml>src/main/amazon-scrapi/WEB-INF/web.xml</webXml>
<failOnMissingWebXml>false</failOnMissingWebXml>
<webappDirectory>src/main/webapp</webappDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>

View File

@ -1,12 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Amazon Scrapi</title>
</head>
<body>
<h2>Amazon Scrapi</h2>
<hr />
<p>An API interface with amazon.com using webscraping</p>
</body>
</html>

View File

@ -1,46 +0,0 @@
package com.veritablevalor.blizliam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
public class AmazonRepository {
Playwright _playwright;
Browser _browser;
Page _page;
boolean _loggedIn = false;
Logger _logger;
final String AMAZON_URL = "https://amazon.com/";
public AmazonRepository()
{
Logger logger = LoggerFactory.getLogger(getClass());
_logger = logger;
_logger.info("Amazon URL: " + AMAZON_URL);
_playwright = Playwright.create();
_browser = _playwright.chromium().launch();
//_page = page;
}
public void AuthIfNeeded(String redirectUrl)
{
Page page = _browser.newPage();
page.navigate(AMAZON_URL);
boolean loggedIn = page.getByText("Hello, sign in").count() <= 0;
if (loggedIn)
_logger.info("Already Logged in as: ");
else
_logger.info("Not logged in...");
}
}

View File

@ -1,7 +1,6 @@
package com.veritablevalor.blizliam;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@ -9,46 +8,11 @@ import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;
@WebServlet(
value = "/hello",
name = "hello"
)
public class App extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String url = "https://amazon.com";
AmazonRepository _repo = new AmazonRepository();
_repo.AuthIfNeeded("");
PrintWriter out = resp.getWriter();
/*
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch();
Page page = browser.newPage();
page.navigate(url);
boolean loggedIn = page.getByText("Hello, sign in").count() <= 0;
System.out.println(page.title());
out.println("Here is the page.title: " + page.title());
if (loggedIn)
{
out.println("Logged in");
}
else
{
out.println("Logged out");
}
}*/
out.println("Hello!");
out.close();
}
}