Google Site Search + MY search input box - javascript

I am using Google Site Search (the paid one, not Google Custom Search) with a simple search input box…mine, not Google’s.
Here is my very basic input box:
<div id="search">
<form action="http://????????.com" method="GET">
<input type="text" class="input" name="q" placeholder="Search...">
<input type="submit" value="Search">
</form>
</div>
The Google Site Search script is something along this order:
<script>
(function() {
var cx = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:searchresults-only></gcse:searchresults-only>
I am (obviously) not a programmer…otherwise, I’m certain the answer to this would be quite evident. However, can anyone tell me what the HTML requires to pass the search text entered to the script? Directing the “action=” to www.google.com/search working just fine, if I’m wanting an internet-wide search. However, I want to confine the search to the site (hence, Google Site Search).
Thanks, in advance, and please advise if I need to clarify any points here.

Related

Searching on a website returns a sooqr popup with results, how do I scrape this?

There is a site (https://www.schoolmaterialen.nl) I would like to scrape for specific items using beautifulsoup python. I can query the item I want using the url: https://www.schoolmaterialen.nl/#sqr:(q[9789053001813]), but instead of showing a page with results, it shows a popup using sooqr and the results can't be found in the html code I obtained using beautifulsoup. The only mention of the sooqr popup in the found code is this:
<!-- Start Sooqr.com on-site search and navigation code -->
<script>
document.addEventListener("DOMContentLoaded", function() {
document.getElementsByClassName("keywords")[0].setAttribute("id", "search");
});
var _wssq = _wssq || [];
_wssq.push(['_load', {'suggest': {"account":"SQ-119341-1","fieldId":"search","version":4}}]);
_wssq.push(['suggest._setPosition', 'screen-middle']);
_wssq.push(['suggest._setLocale', 'nl_NL']);
_wssq.push(['suggest._excludePlaceholders', 'Search..']);
(function () {
var ws = document.createElement('script');
ws.type = 'text/javascript';
ws.async = true;
ws.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'static.sooqr.com/sooqr.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ws, s);
})();
</script>
<!-- End Sooqr.com on-site search and navigation code -->
I already tried to directly use the url of the page I want, but it needs the title of the book which is one of the things I want to find using the isbn. Is there a way to somehow still get the link to the page that is in the popup?

Is it possible to get Google Ads separately (to be used for scripting) for a specific search term using an API?

Aim: Getting Google ads separately to be embedded to a site.
What I tried so far:
1.) Google Custom Search API
→ does not deliver ads but search result
Coding information:
https://developers.google.com/custom-search/v1/cse/list
Code for getting search results:
function requestSearchResult() {
jQuery.get("https://www.googleapis.com/customsearch/v1/", {
q: SearchTerm,
cx: "01042***5fgs",
key: "AL***Xra",
},
function(items, status) {
document.getElementById("content").innerHTML += "" + items.items[0].htmlTitle + "";
document.getElementById("content").innerHTML += "<br>" + items.items[0].displayLink;
document.getElementById("content").innerHTML += "<br>" + items.items[0].htmlSnippet;
document.getElementById('content').innerHTML += "<br>" + '<img src="' + items.items[0].pagemap.cse_thumbnail[0].src + '" alt="text mode" />';
...
...
});
2.) Custom Search Element Control API
→ does not deliver ads separately but it is possible to embed a search box and/or search results together (not separately) with ads to a site, the search results and ads cannot be handled for further scripting
Coding information:
https://developers.google.com/custom-search/docs/element
Code for a search box:
<script>
(function() {
var cx = '01743***hxm';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:searchbox-only></gcse:searchbox-only>
Code for search results:
<script>
(function() {
var cx = '01743***hxm';
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
})();
</script>
<gcse:searchresults-only></gcse:searchresults-only>
If you just need ads, take a look at https://developers.google.com/custom-search-ads/
If you're looking to use Custom Search, but want more control over rendering, use the Custom Search Element Control API and the recently introduced callbacks feature: https://customsearch.googleblog.com/2019/06/introducing-callbacks-for-even-more.html
Note that for policy reasons this does not provide any control over Ads rendering -- Ads must be rendered as provided.
Thanks, these links are helpful, just did not find them before:
explanation with example code:
https://developers.google.com/custom-search-ads/web
code generator for specific settings:
https://developers.google.com/custom-search-ads/web/code-generator
#Andy: I will check it in detail now and try to set it all up. Are you interested in working together with me (of course not for free :-))? That would save a lot of time I think :-) If yes, please get in contact with me (h.gruenbacher#gmail.com)!

Google plus badge TypeError: a is undefined

The google plus badge sometimes it render okay with no errors, sometimes it doesn't render and give this error in the console :
TypeError: a is undefined
...pi.auth,e={client_id:c,session_state:b};a.checkSessionState(e,function(b){var c=.
My code is :
< div class="g-page" data-href="https://plus.google.com/+google"
data-theme="dark" data-showtagline="true" data-showcoverphoto="true"
data-rel="publisher" >
<!-- Place this tag after the last widget tag. --><script type="text/javascript">
window.___gcfg = {
lang: 'de'
};
// just put this in here
document.getElementsByClassName('g-page')[0].setAttribute('data-width', document.getElementById('google-badge').clientWidth);
(function () {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'https://apis.google.com/js/platform.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
EDIT:
the a is defined in the google api here : https://apis.google.com/js/platform.js
I have the same problem. I think google badge library somehow conflicts with other javascript libraries like AngularJS.

Set Google +1 button url with javascript

I am building an image gallery that is slider based and loads new images via javascript and have a requirement to set the Google +1 button's URL via javascript so +1 can be set on each image.
I also need to reload the +1 button based on each image (the url will have a querystring parameter containing the image id to make it unique). Is this possible?
<!-- Place this tag where you want the +1 button to render -->
<div class="g-plusone" data-annotation="inline" data-href="#"></div>
<!-- Place this render call where appropriate -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
You can use the following code to alter the gplus href attribute using jQuery. Make sure to include jquery library first and then use the code below:
<script type="text/javascript">
jQuery(".your-button").click(function(){
jQuery(".g-plusone").attr("data-href","Your-Value-Goes-Here");
});
</script>
Write this in head tag:
// Load +1 script
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
The HTML Code:
<div id="plusone_container">
</div>
And write this jQuery anywhere you want to set +1 button's url:
$("#plusone_container").html('<div id="plusone"></div>');
gapi.plusone.render("plusone", { "href": "Your URL" });

Cannot click Google 1 button on my site

I just created a website for a new business that I will run, I try to set the Google 1 button, however even if it's correctly displayed I cannot click it. Does anyone know something about this problem?
Feel free to check the page http://mini-site.ca.
<script type="text/javascript">
(function() {
var po = document.createElement('script');
po.type = 'text/javascript';
po.async = true;
po.src = 'apis.google.com/js/plusone.js';;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
</script>
Just edit the "< fb:like width="50"..." (facebook tag for like / send buttons)
<fb:like href="http://www.mini-site.ca" send="true" layout="box_count" width="50" show_faces="true" font="arial" class=" fb_edge_widget_with_comment fb_iframe_widget">
Like this.

Categories

Resources