Indexing ASYNC JavaScript content - javascript

Is there a technic existing to index AJAX content with google bot? I mean, is it possible to declare a method in javascript that the bot will call and execute to get page content?

No.
The sensible approach to dealing with this is to create real pages that express the state of the document is in after being manipulated with JavaScript, to link to them as normal and then progressively enhance with JavaScript to:
Cancel the normal action of the link
Modify the DOM
Change the URL in the address bar

Related

Wait for the JS to be executed before scraping the page

I'm trying to scrape the following page using hQuery: http://www.oddsportal.com/search/Paris+SG/soccer/
I realised half way that the odds of each game are included using JS (before, it's just -). Is there any way to get the page after the javascript has been executed or should I find another website??
My guess is that you would have to use another browser (not hQuery) and look into the code and see if there are any events that are emitted that you can catch up on.
You cannot using PHP
Scraping a site gives you whatever the server responds with to the HTTP request that you make (from which the "initial" state of the DOM tree is derived, if that content is HTML). It cannot take into account the "current" state of the DOM after it has been modified by Javascript.
You can using other powerful tools like selenium
You would need PhantomJs PHP wrapper for that is easy to use and gives more control and features, please see my answer here
Scraping a dynamically loading website with php curl
Hope it helps

Suitescript within iframe

I have a suitelet that is adding an inlinehtml field which contains an iframe. The problem is when I try to use the API functions I get an error in the browser.
For example just trying to do
var value = nlapiLookupField('customer', custid, custentity_mycustomfield');
Results in nlapiLookupField is not defined. Is there a way I can access the API by writing functions within my HTML page being called as an iframe? I'm open to suggestions, if there is a way I can include the functions as part of the suitelet and call them from the iframe I would do that but so far have not gotten it to work.
If your iframe is all custom HTML then you won't have the suitescript client libs loaded.
I take care of this one of two ways:
Call parent.nlapi...
Load your iframe from a suitescript. This can be a really simple form with room to load your custom HTML
Of course if you go the second route why do you need the iframe? You carload quite a bit of custom HTML into a div inside an inline HTML field. In my experience that simplifies things quite a bit.

Use Site Property in eSpace Javascript

I included Google Analytics (javascript) in my Outsystems website via de eSpace Javascript. Now I want to place the Analytics Key in my Site Properties so I can update it easily for every environment.
How can I use a Site Property in my Javascript?
You can create a site property to store the Tracking ID.
site Property screenshot
Second, you need to create a webblock with an unescaped expression, and add your javascript this way:
weblock expression screenshot
Finally, you just need to drag you weblock to each webpage you want to track.
cheers,
Vera
As far as I know, you cannot use Site Properties in the eSpace JavaScript window. For that, you have to use an escaped expression on a web screen or web block to add your JavaScript code along with the use of Site Properties.
Since you want the same script on all the web screens, I suggest that you add this expression in the Footer web block, so that it will be automatically added to all the web screens you create.
I can understand your use case. If I read it correctly, you're trying to use some JavaScript in one espace, that would be run in every page load, something like an
onLoad(function(){
// your Google Analytics code, but using the value from the site property
})
And in this way, you would be able to update the site property without the need to republish all consumers. Seems like a nice approach :)
On way to be able to achieve this, would be to have your JavaScript to request the key on the fly to the server side, and maybe cache it.
This can be easier or harder depending on the Platform version you're running... But here's a simple way to achieve it.
Add the site property to the espace. Build a page that has no layout, and in the preparation, add a download widget that only downloads the value of your site property. In the same espace, in the espace JavaScript, add an AJAX request to the page I was referring to before, and when you get the response back, start your Google Analytics code.
To be able to use this in every other espace, and in every page, you still need to reference something from the Google Analytics espace though, so that espace JavaScript is run in every page
Hope it helps :)

Calling javascript href from mojolicious

I've been given permission to scrape a website to build up a database of products. When a button is pressed, a javascript function is called and then altered information is presented to the user (change in colour, price etc..). When trying to scrape the website, I want to be able to predict the changes as if the button was pressed. The element in question is:
<a id="anId" title="title" class="class" data-code="code" href="javascript:aFunction('ctl00$MainContent$ctl00$ctl00$FabricGroups$ctl00$FabricOptions$ctl00$FabricButton','')"></a>
Within mojolicious (I imagine the userAgent class?), how do I print the output of what calling the javascript function would do? Is it possible?
It certainly isn't easy. Perl does not interpret javascript (at least not usually and almost certainly not with a DOM).
That said, I have been working on a project to help this, WHICH IS DEFINITELY NOT READY FOR PRODUCTION, which tests javascript actions by spawning an instance of PhantomJS. Once complete the api intends to be as easy to use as Test::Mojo already is. I will be presenting it at YAPC::NA later in the year (2015).
Update: The module is now on CPAN, called Test::Mojo::Role::Phantom.

How to load page content by URL using JavaScript

I was asked during an interview to write a piece of code to highlight the url if the content of the url contains a certain keyword. I honestly do not know how I can do that with JavaScript...
I think you can firstly fetch content using ajax, search for keyword,
then highlight the url if necessary.
But this comes with limitation:
The url you want to highlight should allow cross-site ajax fetching.
performance will not be so good, since you need to fetch each url if there are many.
If the targeting url is client-side rendering, fetching its html simply won't see the content since its not render yet.
Normally we won't solve this using front-end approach, but using search-engine indexing method instead.

Categories