【发布时间】:2016-01-05 10:20:20
【问题描述】:
我最近尝试使用 WebView 从 html 中提取数据并遇到了无数问题,所以在搜索后我发现了一个名为 Selenium 的完整库,其中包含许多不同的浏览器驱动程序,例如 Mozilla、Chrome、IE 和它还使请求切断了应用程序的 HTTPRequest 部分,它还完成了解析 HTML 的工作,因为它有一个内置的 HTML 解析库,它非常实用,唯一完全阻止我的问题是事实上它一直强制关闭我的应用程序,这是我的课程:
package com.myapp.webscraper;
import com.myapp.webscraper.AppConfig;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Analytics extends AppCompatActivity{
AppConfig cfg = new AppConfig();
//WebView Analytics = null;
EditText console = null;
@Override
public void onCreate(Bundle l){
super.onCreate(l);
if(cfg.useDebug)
{
setContentView(R.layout.analytics_debug);
String content = "Yellow";
EditText output = (EditText) findViewById(R.id.debug_analytics_output);
WebDriver driver = new FirefoxDriver();
//driver.get("http://google.co.uk");
// WebElement body = driver.findElement(By.cssSelector("body"));
// String content = body.getText();
output.setText(content);
}
else
{
setContentView(R.layout.analytics);
}
if(cfg.useDebug)
{
//console.setText(console.getText() + "\n[URL LOADED]: " + Analytics.getUrl() + "\n");
}
else
{
}
}
}
如果这个库不能在 Android 上运行,您能否推荐任何替代品或库来推动我的应用程序向前发展,完成这项工作至关重要,非常感谢。
【问题讨论】:
标签: java android html selenium