Arsenic async API : session.get_screenshot() to capture image in particular location - web-scraping

I have been trying to take screenshot of captcha based on ID from URL https://elegalix.allahabadhighcourt.in/elegalix/WebStartCaseSearch.do in arsenic async web driver.
async with get_session(services.Chromedriver(), self.browser) as sesssion:
await session.get("https://elegalix.allahabadhighcourt.in/elegalix/WebStartCaseSearch.do")
#Below gives <_io.BytesIO object at 0x7f6625119f68>. How to retrieve captcha image from this object
captcha_image = session.get_screenshot()
But as per API documentation of Arsenic https://arsenic.readthedocs.io/en/latest/reference/session.html,
get_screenshot() :
Coroutine to take a screenshot of the top-level browsing context’s viewport. Return type: io.BytesIO
we can only take entire page of screenshot, I would like to know any way to take particular image element ID and store it as base64 as we do it in Selenium below.
captcha_image = driver.find_element_by_id(
'captcha_image'
).screenshot_as_base64

Related

Understand Dynamic Links Firebase

I would like to understand better Firebase Dynamic Links because i am very new to this subject.
What i would like to know :
FirebaseDynamicLinks.instance.getInitialLink() is supposed to return "only" the last dynamic link created with the "initial" url (before it was shorten) ?
Or why FirebaseDynamicLinks.instance.getInitialLink() doesn't take a String url as a parameter ?
FirebaseDynamicLinks.instance.getDynamicLink(String url) doesn't read custom parameters if the url was shorten, so how can we retrieve custom parameters from a shorten link ?
My use case is quite simple, i am trying to share an object through messages in my application, so i want to save the dynamic link in my database and be able to read it to run a query according to specific parameters.
FirebaseDynamicLinks.instance.getInitialLink() returns the link that opened the app and if the app was not opened by a dynamic link, then it will return null.
Future<PendingDynamicLinkData?> getInitialLink()
Attempts to retrieve the dynamic link which launched the app.
This method always returns a Future. That Future completes to null if
there is no pending dynamic link or any call to this method after the
the first attempt.
https://pub.dev/documentation/firebase_dynamic_links/latest/firebase_dynamic_links/FirebaseDynamicLinks/getInitialLink.html
FirebaseDynamicLinks.instance.getInitialLink() does not accept a string url as parameter because it is just meant to return the link that opened the app.
Looks like there's no straightforward answer to getting the query parameters back from a shortened link. Take a look at this discussion to see if any of the workarounds fit your use case.

How do I pass Parameters in Dynamic Links?

How to receive parameters from firebase dynamic links in flutter?
I created a short url:
https://subdomain.example.com/product
which points to
https://example.com/view-product
But I want to add a url query parameter like:
https://example.com/view-product?id=56
Note that "56" is variable and changes dynamically inside app flow. I am unable to receive this "id" parameter.
On browser I tried entering https://subdomain.example.com/product?id=56
I received the link: https://example.com/view-product
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
showModalBottomSheet(context: context, builder: (context){
return Container(
height: 100.0,
child: Text(deepLink.toString()),
);
});
if (deepLink != null) {
debugPrint("Link found on line: "+deepLink.queryParameters.toString());
}
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});
I finally figured it out!
I was understanding the concept totally wrong here.
There are 4 ways as of now to create dynamic links.
1) Firebase Console
2) Manually
3) Rest API
4) Dynamic Link Builder API on iOS and Android
What I was doing wrong here is was, I created https://subdomain.example.com/product a dynamic link from firebase console and was testing it against a manually created link.
2nd method(Manually) is much more powerful is you need to link dynamic content from your website links.
https://your_subdomain.page.link/?link=your_deep_link&apn=package_name[&amv=minimum_version][&afl=fallback_link]
The above mentioned is the standard manual procedure for creating dynamic links.
Lets break down the above link so that it looks less scary:
https://your_subdomain.page.link ==> This is simply your subdomain you registered on firebase console. In our case it's https://subdomain.example.com
link=your_deep_link ==> your_deep_link is basically your deep link(the link you want to open with that exists on your server, it can contain all the parameters you need). In our case its https://example.com/view-product?id=56. But note that this link is to be embedded inside an url so it needs to be urlencoded first. Use any url encoder for this purpose. The resulting encoded string becomes
https%3A%2F%2Fexample.com%2Fview-product%3Fid%3D56
apn=package_name ==> your respective package name for IOS or Android
[&amv=minimum_version] ==> "[]" represent this as an optional parameters. This parameter is the minimum version number of your app that you want your app should respond to this dynamic link (0 if you want all versions to support)
[&afl=fallback_link] ==> ==> "[]" represent this as an optional parameters. This is the fallback url, again url encoded. Could be your android play store link.
So our final dynamic link looks like:
https://subdomain.example.com/?link=https%3A%2F%2Fexample.com%2Fview-product%3Fid%3D56&apn=com.example&amv=0

Firebase Storage : Get the token of the URL

I currently have an application that works with Firebase.
I repeatedly load profile pictures. However the link is quite long, it consumes a certain amount of data. To reduce this load, I would like to put the link in raw and only load the token that is added to the link.
To explain, a link looks like this: “https://firebasestorage.googleapis.com/v0/b/fir-development.appspot.com/o/9pGveKDGphYVNTzRE5U3KTpSdpl2?alt=media&token=f408c3be-07d2-4ec2-bad7-acafedf59708”
So I would like to put in gross: https://firebasestorage.googleapis.com/v0/b/fir-developpement.appspot.com/o/
In continuation: “9pGveKDGphYVNTzRE5U3KTpSdpl2” which is the UID of the user that I recover already and the or my problem this poses: “alt = media & token = f408c3be-07d2-4ec2-bad7-acafedf59708” which adds randomly for each photo .
I would like to get back only this last random piece …
Is it possible ?
Thank you
UP : 01/11 Still no solution
It's not supported to break apart and reassemble download URLs. You should be treating these strings as if their implementation details might change without warning.

Limiting the response from Google Cloud Vision API

Currently using the google cloud vision api for pulling text from images of documents.
Current situation - the API works great, and returns tons of data including the bounding boxes of where the words are located.
Desired outcome - to query only the words pulled from the image and not all the meta data about where the bounding boxes and vertices of the words are (it's like 99% of the response and comes out to be about 250k which is a huge waste when all I want are just the words)
const vision = require('#google-cloud/vision');
const client = new vision.ImageAnnotatorClient();
// Performs label detection on the image file
client
.documentTextDetection('../assets/images_to_ocr/IMG_0942-min.jpg')
.then(results => {
console.log('result:', result);
})
.catch(err => {
console.error('ERROR:', err);
});
For now, the Google Cloud Vision client library for nodeJS does not have an option for requesting partial responses like the ones you are asking.
Anyway, if you just want to show the text and not any of the other metadata, you can filter the response like this:
const fullTextAnnotation = results[0].fullTextAnnotation;
console.log(`Full text: ${fullTextAnnotation.text}`);
You will get the full response in 'fullTextAnnotation', then you can get fullTextAnnotation.text to get only the text with ‘\n’ characters to separate the text blocks, without any metadata.
In case you are interested in using something else instead of nodeJS, the Java client library has the setFields() method for the Annotate class and also from the API Explorer you can use a partial fields mask to see the effect.

Store Locator API + Geolocation

I am trying to create a Store Locator with the Google API, very similar to the one in the Google examples here:
http://storelocator.googlecode.com/git/examples/panel.html
However I've hit a wall trying to get the Store Locator API to get the user's position through Geolocation, so when I click on Get Direction in the infowindow I get directions to the user position; instead of having to type my address in the: Where are you? Panel box.
In the documentation what I have seen is that geolocation is a boolean in the View Option that is set to True by default. But this does not solve my problem.
Does anyone have any idea on how to do this?
seems that the googlecode page you said is no longer exist. So I can't give any further insight about what you want to make.
However, by your description, Luckily I made similar site few months ago. It is on Grocery Store Near Me .
The concept of Geolocation is an HTML5 (actually W3C) Geolocation API which is now already embed in most modern browser. It is an API which you can obtain user's location (latitude, longitude, altitude, and accuracy).
you can call it with simply
navigator.geolocation.getCurrentPosition(success, error, geo_options);
Success and error is a callback function in which you can define.
In my case, the function looks like these
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
// use the lat and long to call function to fetch an API through AJAX
fetchStoreData(latitude, longitude);
}
In the Store Locator schema (like mine in Grocery Store Near Me), Geolocation is used to obtains user lat and long. The lat and long, then send to server via AJAX to get data about nearby store location.
The server serve an API in which accept lat and long as parameter, then fetch the store data (either using database, or other external API like foursquare), then you can display it either on list, or on a maps.

Resources