How to get the URL of image using Google Custom Search Engine - google-apis-explorer

I'm trying to build a custom image search using Google's CSE and I'm facing some difficulties getting the URL from the result box.
I have already created a new search engine and implemented the code on my web page.
The results are showing properly and the search engine is working as intended.
Now what I would like to get is:
Avoid opening the picture on another window
Click on the image and get the real URL of the picture (not encrypted)
Display selected url on alert window
What I found so far exploring the source code is that the result image items URL links are encrypted and not showing the real URL of the image.
The following code is the result of searching the same dog using my custom search engine with Google's API and Google image search web page.
The img result using my custom search engine
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQmjyo4iFP_SQ-a2u7piFW8hZ_J4CEtDMF6_dE8Ev-RvqcZlA93DIo6uQo" title="How dogs contribute to your health and happiness" class="gs-image gs-image-scalable" style="width: 126px; height: 84px;">
The img result using Google's web image search
<img class="irc_mi" src="https://cdn1.medicalnewstoday.com/content/images/articles/322/322868/golden-retriever-puppy.jpg" onload="typeof google==='object'&&google.aft&&google.aft(this)" alt="Image result for dogs" width="529" height="353" style="margin-top: 0px;" data-iml="1552180024897">
Note that src parameter in one is encrypted and not in second one. If I do the same search on Google image I can get the real URL from the src.
So my question is: How to get the real image URL using Google's CSE? Is there any way I can get the original URL?
I have gone through this the documentation https://developers.google.com/custom-search/v1/cse/list but is not clear to me how to implement the Optional query parameters. Maybe with "linkSite" query parameter?
Best regards and have a nice day!

Related

Automatically translate a site

I have a site and have the need to automatically translate it in many supported language (english,spanish,french) to my user.
User (a few selected people) access the site through a link i provide, so is not an issue distribute an ad-hoc link.
I have tried to use Google Translate and all work fine, unless some piece of the site use javascript and received encoded resources from third party.
So for example think i have a static site that i can't translate by translating files on web server (i need to translate them on the fly).
We can say the site the is the following :
<html>
<script>
function show()
{
// Will produce a messagebox with say "test"
eval(String.fromCharCode(97,108,101,114,116,40,39,116,101,115,116,39,41,59));
}
</script>
<button onclick="show()">
Show me
</button>
</html>
If i try to google translate it the 'Show me' label correctly translate but message box does not (in my scenario there are no messages box but the concept is the same, a third party send me encoded data on some event, and display it).
Is there a way to automatically translate such kind of page in my scenario?

Fetching HTML or links from a website via Json/HtmlUnit

I have been trying to extract the html values from a page e.g. https://www.qwant.com/?q=cat&t=web but when I use jSoup or HtmlUnit I always get a basic page that doesn't compare to what is generated when I search via my normal browser.
My codes in general work on other websites but could someone explain to me why when I visit the above with code that I don't get the same results? I am trying to fetch all the url values on the page. Is it to do with javascript?
WebClient wb = new WebClient(BrowserVersion.FIREFOX_52);
wb.getPage(url);
wb.waitForBackgroundJavaScript(25000);
System.out.println(wb.getCurrentWindow().getEnclosedPage().getWebResponse().getContentAsString());
Some website just won't allow you to parse them headlessly (for obvious reasons). As I tried to curl the Qwant cat result page, the result was a blank page.
But you want to give a try at switching from Firefox to Chrome as your browser : It is not possible to detect and block Chrome headless

Can I make a Rainmeter widget that fetches the nearest/town or city via HTML5 geolocation?

I'm trying to build a Rainmeter widget that fetches the nearest town to the user and displays it onscreen. I'm currently trying to use the webparser function and this website, but it doesn't seem to be working. The code I've adapted from the example on the Rainmeter website is below - any ideas?
[Rainmeter]
Author=Rainmeter staff
Update=1000
;[WEBSITE MEASURES]===============================
[MeasureWebsite]
Measure=Plugin
Plugin=WebParser
UpdateRate=1800
URL=http://locationdetection.mobi/
RegExp="(?siU)<span style="color:white;">town_city:</span> <b>"(.*)"</b>.*"
[MeasureTown]
Measure=Plugin
Plugin=WebParser
Url=[MeasureWebsite]
StringIndex=1
;[DISPLAY METERS]==================================
[TextStyle]
X=2
Y=17
FontFace=Segoe UI
FontSize=32
FontColor=#454442
StringStyle=Bold
Antialias=1
[MeterTown]
MeasureName=MeasureTown
Meter=String
MeterStyle=TextStyle
Y=2
I'm not sure if it's too late but... your URL doesn't seem to contain any town_city information... at least not in the source code.
Rainmeter reads the raw HTML code from the URL you give to it and processes it through the provided RegEx. Without proper information in the website you can never get it to work.

FB Share without App ID

Is it possible to use FB share plugin without APP ID?
If I use HTML5 code then the console logs an error FB.getLoginStatus() called before calling FB.init().
To use HTML 5 FB like is it necessary to have an APP ID?
Thank you
Here i am sharing what i did to share post on fb wall, In this way you do not need to use appId. Just put this code in your HTML page where you want link to share...
<a name="fb_share" type="button" href="http://www.facebook.com/sharer.php?u={$url}&media={$imgPath}&description={$desc}" class="joinFB">Share Your Advertise</a>
URL parameters are as explained below,
u : url or link you want to user to go when he clicks on your wall post,
media : full image path,make sure that image is available on given path,it will accept one image only
description : a short description that you want to show on wall
It will also ask you to write some data which will be displayed above your post. Description passed in url will be displayed in right side of your image.
Please note that i had passed $url,$desc,$imgPath variables as per my need. The above code is in smarty-php, so change it as per your requirement.
Hope this becomes helpful to you.
Yes you need an app id. You can try to inject your own code into the DOM of the user when using facebook and call functions in their javascript... But I doubt many users will actiually use an "app" that works this way.

Google static map is not displaying

I am listing lots of businesses and their static google maps in my page (with a pagination). While going through the pages, sometimes Im getting the following image instead of maps. And if I refresh the page again, I will get the correct maps.
I am sure that I have not reached the usage limit (because Im getting the same maps on page refresh).
My sample request is given below . (Note: I am not passing any API key. Is it really required ? )
<img src="//maps.googleapis.com/maps/api/staticmap?center=168 Palmers Lane Pokolbin,POKOLBIN,NSW,2320,Australia&zoom=11&size=240x180&maptype=roadmap&sensor=false" />
Pass encodeURI-ed urls to src:
<img src="//maps.googleapis.com/maps/api/staticmap?center=168%20Palmers%20Lane%20Pokolbin,POKOLBIN,NSW,2320,Australia&zoom=11&size=240x180&maptype=roadmap&sensor=false" />