package org.jeecg.modules.spyderUtils.spider;

import lombok.extern.slf4j.Slf4j;

import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.Duration;


@Component
@Slf4j
public class ReportSpyder {


    @Autowired
    private CreateChromeDriver createChromeDriver;

    private String scriptStrwebdriver = "window.navigator.webdriver=undefined";

    public String companyReportMessage(String url) throws InterruptedException {
        RemoteWebDriver driver = createChromeDriver.createChromeDriver();
        String pageSource = null;
        try {
            driver.executeScript(scriptStrwebdriver);
            driver.get(url);
            // 等待页面加载完成
            new WebDriverWait(driver, Duration.ofSeconds(5));
            Thread.sleep(700);
            String title = driver.getTitle();
            System.out.println(title);
            pageSource = driver.getPageSource();
        }catch (Exception e){
            e.printStackTrace();
        }
        try {
            driver.quit();
        }catch (Exception e){

        }
        try {

        }catch (Exception e){
            driver.close();
        }
        return pageSource;
    }
}
