记录一次定时任务开启线程池+selenium java爬取裁判文书网

package com.bicon.panwen;

import com.bicon.config.RedisBloomFilter;
import com.bicon.dao.PanwenMapper;
import com.bicon.xpath.exception.XpathSyntaxErrorException;
import com.bicon.xpath.model.JXDocument;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.By;
import org.openqa.selenium.UnhandledAlertException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.*;

@Component
public class Crawl2222 {

    private static final Logger logger = LoggerFactory.getLogger(Crawl2222.class);
    private static FirefoxBinary firefoxBinary = new FirefoxBinary();
    private static FirefoxOptions firefoxOptions = new FirefoxOptions();
    private static String SUFFERFIX = "http://wenshu.court.gov.cn";
    private  static String YANZHENGMAURL ="http://wenshu.court.gov.cn/waf_verify.htm";

    //并发执行队列
    private static LinkedBlockingQueue<String> urlQueue = new LinkedBlockingQueue<String>();

    //创建线程池的队列,最小,最大,线程空闲时间 结束继续存活时间
    static BlockingQueue<Runnable> queue = new LinkedBlockingDeque<Runnable>();
    static ThreadPoolExecutor executor;

    static  CountDownLatch endGate;

    @Resource
    private PanwenMapper panwenMapper;

    //创建

    public  void init() throws InterruptedException, XpathSyntaxErrorException {
        String html = "";
        String driverPath = "E:\\geckodriver.exe";
        System.setProperty("webdriver.gecko.driver", driverPath);
        //不弹出浏览器
        firefoxBinary.addCommandLineOptions("--headless");
        firefoxOptions.setBinary(firefoxBinary);

        FirefoxDriver driver0 = new FirefoxDriver(firefoxOptions);
        // WebDriver driver = new FirefoxDriver();
        //定位对象时给10s 的时间, 如果10s 内还定位不到则抛出异常
        driver0.manage().timeouts(
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值