how to use htmlunit with my android project
Asked Answered
M

4

5

I have downloaded htmlunit 2.11 zip. i have extract it. then i have tried to paste them in my project's libs folder. from the libs folder i have added them in build path. then i get this error, while i was trying to run my app

conversion to dalvik format failed with error 1

then, from stackoverflow i found that, one said to delete xalan xercesImpl xml-apis. i deleted them. but getting this error:

Error generating final archive: Found duplicate file for APK: about.html

error message also showed that which files are conflicted. they are jetty-http jetty-io jetty-util jetty-websocket then i run my app again. this time it shows some warning. i have ignored them. but my app crash saying that classNotFound

by the way, i have also deleted httpclient jar. because one said that httpclient is already built in android.

this is my problem. Now, can anyone help me? i really want to use htmlunit in my app

Edited:

it will be very helpfull if you show me the steps, 'how to add htmlunit in my project'

Edited 2:

mainly i have a link, which i have get after login (i have login through web view) this link give me a simple page. in that page there is a textarea and a submit button. and there are some javascript too (i think these javascript run, when i press the submit button). i can do it through webview, but for some reason i don't want to use webview. whene i press submit button, it deliver the value of textarea and some value of hidden field with existing cookies(which are get when i logged in through webview) Post method. i need to do this without webview. now is there any other option beside htmlunit ?? i heard about HttpClient, HttpUrlConnection. one more thing, agter submitting it will redirect me to another page. i don't need to do anything with this redirected page.

N.B: if this question is not appropriate with what i really ask previously, then you can suggest me, and i will post a new question. thank you

Mesdemoiselles answered 14/2, 2013 at 22:40 Comment(0)
M
2

sorry, i have lost all my hope on HTMLUNIT. :( to gain my goal i have used HttpUrlConnection & Jsoup ... that works for me. here is my procedure i have post my code in answer.

Mesdemoiselles answered 7/4, 2013 at 22:0 Comment(0)
S
6

Nothing of this will work because he is trying to include HtmlUnit into a android project. HtmlUnit is not compatible with android because is refernces some java.* & javax.* classes which are not available in android.

Hope there will come a version for android.

Selfappointed answered 4/2, 2015 at 19:49 Comment(1)
Thanks you :) lets hope for android version :DMesdemoiselles
M
2

sorry, i have lost all my hope on HTMLUNIT. :( to gain my goal i have used HttpUrlConnection & Jsoup ... that works for me. here is my procedure i have post my code in answer.

Mesdemoiselles answered 7/4, 2013 at 22:0 Comment(0)
M
1

Here are the steps to follow:

  1. Download the latest version of HtmlUnit from http://sourceforge.net/projects/htmlunit/files/htmlunit/2.11/
  2. Unzip downloaded file
  3. Go to lib folder --> Right click on htmlunit-core-js-2.11.jar and select 'copy'
  4. Go to Package Explorer in Eclicse --> Chose your project --> Right click on libs folder and select 'paste'
  5. Right click on the newly added file and click on 'Add as a library...' and select your project.
  6. Repeat steps 3, 4 and 5 for the htmlunit-2.11.jar file
  7. Add this two imports to your project:

    import com.gargoylesoftware.htmlunit.WebClient;

    import com.gargoylesoftware.htmlunit.html.HtmlPage;

  8. Clean the project.

Please also check this link http://www.aviyehuda.com/blog/2011/05/16/htmlunit-a-quick-introduction/ for the htmlUnit quick introduction

Michel answered 15/2, 2013 at 0:27 Comment(4)
S : now i am getting this error: 02-15 06:41:13.612: E/AndroidRuntime(27796): Caused by: java.lang.NoClassDefFoundError: org.apache.commons.lang3.StringUtils Mesdemoiselles
NoClassDefFoundError is one of the most common error in Java. Please check this tutorial to resolve it javarevisited.blogspot.com/2011/06/…Michel
If that doesn't help try to add all the files from downloaded library to your project via build path. Right click on you project and choose 'properties' then go to 'Java Build Path', select 'Libraries' tab and 'Add External Jars' Select everything to add all the libraries. Please don't forget to remove all previously added files from htmlUnit. That should work.Michel
S : sorry, i have lost all my hope on HTMLUNIT. :( to gain my goal i have used HttpUrlConnection & Jsoup ... that works for me. here is my procedure i have post my code in answer.Mesdemoiselles
S
0

I know it's too late to answer, but hopefully my answer will help other newbie's like me who is trying to webscrape in their android app and stumbled upon this thread for a working solution of htmlUnit in android studio. I used a previous version of htmlUnit (2.14) and it worked for me. Why I was trying htmlUnit, and not Jsoup ? because my target webpage had javascript calls, which was not giving a fully loaded html. So, in short: Use a previous version of htmlUnit.

Satem answered 2/5, 2021 at 18:58 Comment(1)
the current version works fine... people forget to include everything htmlUnit comes with...Bridge

© 2022 - 2024 — McMap. All rights reserved.