So I want my app to scrape some data from various sites, and one of them shows a recaptcha.
I was able to detect it in my app but I'm having problems figuring out a way to show the captcha to the user. The site is loaded in background with AndroidHttpClient.
I did some research and found nothing that could help me accomplish this for a third party site. The captcha needs to be solved and my quasi-browser (the androidhttpclient which just loads a bunch of sites in background) needs to get access to the site to gather the needed data.
I'm doing a similar project and I used a bitmap to capture the image (captcha) e show to the user in Android.
public Bitmap getCodigoCaptcha(String src){
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(inputStream);
return myBitmap;
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
I get this bitmap from the url that I need and set a ImageView in Android to show to the user.
Why not use a TSimpleCaptcha or JCaptcha?
Related
here is url ...
https://api.thingspeak.com/update?api_key=R3LQP7IXIXEQ1OIV&field1=0
Actually..I don't want to get the content of url.
I just want to update the value of field1 to 1 and 0.
If I just type this url in any broswer,my thingspeak data will be update.All I need to do is to write code like typing in any broswer of this url.
In that way I think I can turn on and off my led through android application for my IOT project.I think all I need to do is to make connection between apk and thingspeak from this url.I am new to android studio.I have tried many ways.Help me please.
Thanks a lot.
You can simply use a HTTP GET method (that is what your browser does).
To answer your question:
try {
// create the HttpURLConnection
url = new URL(yourUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// just want to do an HTTP GET here like your browser would
connection.setRequestMethod("GET");
// give it 15 seconds to respond
connection.setReadTimeout(15*1000);
connection.connect();
} catch (Exception e) {
e.printStackTrace();
throw e;
} finally {
connection.disconnect();
}
There are better (cleaner) ways to do his, but this should answers your question.
PS: Be aware that in Android you will not be able to do this on the main thread! You should do this in a AsyncTask, AsyncTaskLoader, ...
I am currently doing a small app for fun while playing around with the UIs and several other things in android studio. I tried to load a image based on an url with this code:
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setAllowUserInteraction(false);
connection.setRequestMethod("GET");
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
However this will throw a FileNotFoundException for certain urls. I am guessing that is due to the webpage checking the client for certain conditions. One example is this image:
https://kissanime.to/Content/Mobile/images/logo.png
It works fine when loading it via the webbrowser though.
I do not own this page, so I do not know what is causing this issues. Is there any way to debug/solve this?
//EDIT: It seems that the website returns a 503 statuscode when using the HttpURLConnection
//EDIT 2: After inspecting the response message it seems like the webpage contains some type of javascript that loads the image after a 5 second delay
I am still a beginner in Android and java. I am trying to load an image from a server by using AsyncTask. The size of the image is around 50kb. Yet it takes several seconds to show up. The following code is used to download the image from the server.
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BufferedInputStream bis = new BufferedInputStream(input);
Bitmap myBitmap = BitmapFactory.decodeStream(bis);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
Can someone please tell me how to speed up this process. What are the factors this process depends on apart from the network speed?
Thank you in advance.
Firstly, I suggest you to search image size reduce algorithms. Then, you can choose some methologies to load picture. For example, in first step, you can load low sized images. After that , you can load normal size images in background and update each reduced sized images to normal sized images.
Here is a great resource on loading Bitmaps efficiently.
Android Developer site - Loading Large Bitmaps Efficiently
It also includes a code sample.
I want to download an image from server, I am able to download some images but not all, I dont understand why. I have search all over the net but did not find any solution. my code is
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
drawable= Drawable.createFromStream(conn.getInputStream(), "");
I have also tried this code :
bitmap = BitmapFactory.decodeStream(new URL(url).openConnection().getInputStream());
nothing seem to work both bitmap and drawable are null.
Did you check the return code of the HttpURLConnection by using the getResponseCode method? Maybe the resource wasn't found or it contains a redirect.
The following steps allow me to fetch an image kept on my TomCat server. but i am unable to access an image from google's web site . What could be the reason ?
URL aURL = new URL(url);
URLConnection con = aURL.openConnection();
con.connect();
InputStream is = con.getInputStream();
/* Buffered is always good for a performance plus. */
BufferedInputStream bis = new BufferedInputStream(is);
/* Decode url-data to a bitmap. */
bm = BitmapFactory.decodeStream(bis);
bitmapDrawable = new BitmapDrawable(bm);
My URL :http://172.29.26.34:8080/MyService/hb.gif
Google image :
http://www.google.co.in/imgres?imgurl=http://www.androidguys.com/wp-content/uploads/2010/04/android_apps.jpeg&imgrefurl=http://www.androidguys.com/2010/04/25/hardware-standards-android-handset-manufacturers-implement/&usg=__VCGb9CrKDVzOjFJxQ0yFHGewblk=&h=356&w=570&sz=156&hl=en&start=0&sig2=N3UL3C995r94inBx8X822w&zoom=1&tbnid=wISGPUJqRDxB7M:&tbnh=127&tbnw=165&ei=h3-ITKDXMov0vQOsg7GPCQ&prev=/images%3Fq%3Dandroid%2Bimages%26um%3D1%26hl%3Den%26sa%3DN%26biw%3D963%26bih%3D525%26tbs%3Disch:1&um=1&itbs=1&iact=rc&dur=188&oei=h3-ITKDXMov0vQOsg7GPCQ&esq=1&page=1&ndsp=15&ved=1t:429,r:2,s:0&tx=107&ty=75
It is because the google link you pasted is the link for an image viewer in a frame, not for the picture itself. (And actually, strictly speaking the image is not from google website, it was just indexed and displayed by google)
In the right column there is a link 'view full size picture' to go to the real image.
If you use pictures from the web on your website, be sure to check the license if it is acceptable to do so or seek permission.
Set User-Agent
URLConnection con = aURL.openConnection();
con.setRequestProperty("User-Agent","");