我正在尝试使用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'
}
谢谢!
您必须在gradle.build中应用chromedriver目录:
'--webdriver.chrome.driver=/home/nexus/Downloads/chromedriver'
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。