【问题标题】:How can I parse html image in webview to display imageview?如何在 webview 中解析 html 图像以显示 imageview?
【发布时间】:2014-06-06 18:25:10
【问题描述】:

我想在 webview 中获取 html 图片并显示到 imageview。

我不想要一个解决方案以及图片下载的 URL。

我尝试了以下方法。

public class WebViewClientFix extends WebViewClient
{
    private Bitmap bmpCaptcha;
    private Context context;

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler,SslError error) 
    {
        handler.proceed();
    }

    @Override
    public void onPageFinished(WebView view, String url) 
    {
         super.onPageFinished(view, url);
    }

    @Override
    public void onLoadResource(WebView view, String url) 
    {
        super.onLoadResource(view, url);
    }

        public Bitmap getBmpCaptcha() 
        {
        return bmpCaptcha;
    }

    public void setBmpCaptcha(Bitmap bmpCaptcha) 
    {
        this.bmpCaptcha = bmpCaptcha;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }
}

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    webview = (WebView)findViewById(R.id.webView1);
    imageView =   (ImageView)findViewById(R.id.imageView1);

    webview.getSettings().setUseWideViewPort(true);
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setAllowFileAccess(true);
    webview.getSettings().setAppCacheEnabled(true);
    webview.getSettings().setLoadsImagesAutomatically(true);
    webClinent = new WebViewClientFix();
    webClinent.setContext(this);
    webview.setWebViewClient(webClinent);
    webview.loadUrl("https://xxxxx.tr/login");      
}

我应该如何遵循解决方案?

谢谢

【问题讨论】:

标签: android parsing webview imageview captcha


【解决方案1】:

获取页面,解析其内容(jsoup 可能会有所帮助),识别您想要的图像,然后获取它们。

【讨论】:

  • 验证码图片 url esgm.sgk.gov.tr/Esgm/Captcha.jpg 但图片正在更改请求。所以,我必须处理下载的当前验证码图像。 :)
  • 您找到解决方案了吗?我有一个验证码,每次请求都会改变。因此,如果我得到的图像 url 是不够的,因为在第二个请求中图像正在改变。不知何故,我必须提取下载的位图,但我不知道如何......
  • @İsmailKocacan 我也有同样的问题,请问有什么解决办法吗?我尝试使用 javascript 来获取屏幕截图,但没有成功
  • @Coder 我也有同样的问题,请问有什么解决办法吗?我尝试使用 javascript 来获取屏幕截图,但没有成功
【解决方案2】:

这里是示例 https://github.com/ismailkocacan/Android-Captcha-Handler/blob/master/test/src/com/test/captchahandler/MainActivity.java

  • 我在 webview 中使用 html5 画布绘制了相同的验证码图像。 (Javascript 方面)
    • 稍后将canvas图像转换为base64图像字符串(Javascript端)
    • 将base64图像字符串发送到android端并转换为字节图像。

【讨论】:

    猜你喜欢
    • 2017-02-28
    • 1970-01-01
    • 2013-01-22
    • 2023-04-07
    • 2013-04-11
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 2012-09-30
    相关资源
    最近更新 更多