开发者社区> 问答> 正文

Kotlin Selenium Chromedriver不存在

我正在尝试使用Kotlin制作网络抓取应用程序。由于我将要抓取的网站是由JS生成的,因此我一直在尝试使Selenium正常运行,但是我一直为这个错误所困扰。

java.lang.RuntimeException: An error occurred while executing doInBackground()
        at android.os.AsyncTask$3.done(AsyncTask.java:353)
        at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
        at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
        at java.util.concurrent.FutureTask.run(FutureTask.java:271)
        at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.IllegalStateException: The driver executable does not exist: /home/nexus/Downloads/chromedriver
我已经在驱动程序中使用了“ chomd 777”,并在AUR版本中进行了尝试。

这是我的抓取功能的代码

package com.example.nexus.scraper

import android.os.AsyncTask
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver

class Scrap(): AsyncTask<Void, Void, Void>() {
    override fun doInBackground(vararg params: Void?): Void? {
        System.setProperty("webdriver.chrome.driver","/home/nexus/Downloads/chromedriver")
        var driver: WebDriver = ChromeDriver()
        driver.get("www.google.com")
        return null
    }
}

这是我的build.gradle

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.nexus.scraper"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/ASL2.0'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"    
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.41.0'
    implementation 'com.android.support:support-annotations:27.1.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

谢谢!

展开
收起
祖安文状元 2020-01-05 19:03:46 780 0
1 条回答
写回答
取消 提交回答
  • 您必须在gradle.build中应用chromedriver目录:

    '--webdriver.chrome.driver=/home/nexus/Downloads/chromedriver'
    
    2020-01-05 19:04:03
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载