How to get javascript result into php - javascript

I want to use the search engine of different newspapers sites to get all articles of newspapers which are selected by keyword and then delete articles that are too much similar.
I'm trying to use http://www.20minutes.fr/search?q=test search engine but as many other search engine the html result is generated by javascript:
<script>
(function() {
var cx = '011646568010423734157:bmweo2mlsou';
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>
and i cant access the url with curl.
How can i get these url ?
thank you for reading.

Related

How to fetch and display total number of visits for particular page from google analytics?

I want to show the total number of page visits fetched from google analytics for a url like, https://www.example.in/reviews/company.
How can I display the total count using html, javascript?
I added this code in head tag of the page:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-1']);
_gaq.push(['_initData']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>

Hide Search Engine ID for Google Custom Search Element API 2.0

I am implementing Google Custom Search Element API 2.0 in an ASP.NET MVC project. In the documentation they require that the following javascript is included in the view, with the <gcse:search> element following.
<script>
(function() {
var cx = 'xxxxxxxx:yyyyyyyy';
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:search></gcse:search>
However, the search engine id is visible on the line:
var cx = 'xxxxxxxx:yyyyyyyy';
In a browser, selecting View Source (or similar) allows the user to view the script and the search engine id.
How do I ensure that no-one can see my id?
I have found a way around this. By moving the Google script to its own function that takes the Search Engine Id as a parameter:
function buildSearchElement(cx)
{
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);
};
I then call a method on my controller that returns the Search Engine Id upon page load. When this completes, the callback is the buildSearchElement function:
(function ()
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function()
{
if (httpRequest.readyState === 4 && httpRequest.status === 200)
{
buildSearchElement(httpRequest.responseText);
}
}
httpRequest.open("GET", "/GetSearchElementId");
httpRequest.send();
})();

google+ like button isn't working in django template

I used this code for my web page
<div class="g-plusone" size="small"></div>
<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);
})();
</script>
but when I click on g+ button, nothing is happening, i mean no pop-up windows like when we do for facebook/twitter? am i missing something in this code?
No it is working perfectly,
Here is Demo
(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);
})();
Debug the error using chrome developer tool. It is useful.

Google Custom Search - Search on querystring

Google's updated their custom search code last time I looked. Here's our working code:
<script>
(function () {
var cx = '011561302208175438083:iegdgk3oox8';
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:search></gcse:search>
What we want to know, is how do we make this search box automatically search for a value when the page loads?
<gcse:search queryParameterName='q' autoSearchOnLoad='true' noResultsString='no results'></gcse:search>
this will automatically search for the q=MySearchString in the URL

javascript weirdness in IE8, document.write issue

Any idea why putting google plus code this way wont work in IE8 or any other version I guess? Works just fine in firefox though.
live demo: http://jsfiddle.net/9zqsZ/
<script>
var socialString = '<g:plusone size="tall"></g:plusone>';
document.write(socialString);
//google plus share button
(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);
})();
</script>
I am just trying to put it in external file. The weird thing is it just does not work with document.write and works if is placed directly in html. How to implement it in that case?
You could do something like:
<script>
if (navigator.appVersion.indexOf("MSIE") != -1) {
var socialString = '<g:plusone size="tall"></g:plusone>';
var newEle = document.createElement(socialString);
document.body.appendChild(newEle);
}
else {
var socialString = '<g:plusone size="tall"></g:plusone>';
document.write(socialString);
}
//google plus share button
(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);
})();
</script>

Categories