webmagic icon indicating copy to clipboard operation
webmagic copied to clipboard

java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies

Open aaaaaabiao opened this issue 5 years ago • 1 comments

version:0.7.4 ` us.codecraft webmagic-core ${webmagic.version}

    <dependency>
        <groupId>us.codecraft</groupId>
        <artifactId>webmagic-extension</artifactId>
        <version>${webmagic.version}</version>
    </dependency>

    <dependency>
        <groupId>us.codecraft</groupId>
        <artifactId>webmagic-selenium</artifactId>
        <version>${webmagic.version}</version>
    </dependency>

config.ini配置:

What WebDriver to use for the tests

driver=phantomjs #driver=firefox ; driver=chrome #driver=http://localhost:8910 #driver=http://localhost:4444/wd/hub

PhantomJSspecific config (change according to your installation)

#phantomjs_exec_path=/Users/detro/bin/phantomjs-qt5 phantomjs_exec_path=/Users/detro/bin/phantomjs-upstream phantomjs_driver_path=../../src/main.js phantomjs_driver_loglevel=DEBUG

需要使用phtomjs进行抓取。 报错如下: Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/openqa/selenium/browserlaunchers/Proxies at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:178) at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:99) at us.codecraft.webmagic.downloader.selenium.WebDriverPool.configure(WebDriverPool.java:140) at us.codecraft.webmagic.downloader.selenium.WebDriverPool.get(WebDriverPool.java:196) at us.codecraft.webmagic.downloader.selenium.SeleniumDownloader.download(SeleniumDownloader.java:76) at us.codecraft.webmagic.Spider.processRequest(Spider.java:404) at us.codecraft.webmagic.Spider.access$000(Spider.java:61) at us.codecraft.webmagic.Spider$1.run(Spider.java:320) at us.codecraft.webmagic.thread.CountableThreadPool$1.run(CountableThreadPool.java:74) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

有大佬知道怎么回事吗?

aaaaaabiao avatar Jan 26 '21 12:01 aaaaaabiao

解决了,记录一下。 原因是phantomjs用的是com.codeborne.phantomjsdriver这个比较老了和webmagic的selenium不兼容,需要使用新的phantomjsdriver 修改如下

<dependency>
            <groupId>com.codeborne</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.4.4</version>
        </dependency>
<dependency>
            <groupId>us.codecraft</groupId>
            <artifactId>webmagic-selenium</artifactId>
            <version>${webmagic.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.github.detro</groupId>
                    <artifactId>phantomjsdriver</artifactId>
                </exclusion>
            </exclusions>
</dependency>

aaaaaabiao avatar Jan 27 '21 07:01 aaaaaabiao