Buy Button Click Counter [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi and thanks for your time. I have an landing page selling a product (Wordpress Course, for example). When someone clicks on the buy button, he´s redirected to a payment service (paypal like).
What i need from you is a simple thing: an idea (or even a clue) on how to count the number of times the submit button (buy button) is clicked.
I can easily imagine how to count page views with PHP, but is it possible to redirect him to the third party and at the same time reload the initial landing page, to execute my SQL Update Query to count one click, or something like this?

You could use Ajax.
When the button is clicked send an AJAX request to a php page just like others have suggested. However since it is asynchronous, your users won't even notice it.
In terms of code you could just send the ajax request, then redirect to the payment page. Easy and done.
EDIT---
To get info on ajax:
http://api.jquery.com/jQuery.ajax/
http://www.w3schools.com/ajax/

Have the link go to a page on your end, i.e. click.php, that does the SQL update, then redirects to the actual URL you wanted them to wind up on.
Or, just create a bit.ly (or any other URL shortener) URL and use their built-in click tracking for free.

Related

the code of some page is cut when using curl or display the source code of the page [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I explain my problem to you:
When I do PHP curls on some site or want to display the source code of the page element is missing a lot. I think some part is called by a script or something. Could someone help me view the entire code with Curl PHP.
To duplicate my problem go to Facebook or LinkedIn and right click on the page and "View the source code of the page", in this you don't see all the page content but when for example you right click and "inspect an element" You can.
Thank you in advance
CURL can't do this. It's not designed to render HTML or execute JavaScript.
A lot of the content on Facebook, LinkedIn, Twitter and many other pages is loaded through different ways. (like fetch()-requests or WebSocket-Events)
Some nodes you can see in the inspector are not part of the original document (which you are viewing with "view source" or curl downloads). What you see on the inspector is everything currently held in memory, which was partially (or completely) created with a scripting language.
This is basically done to
reduce the load on servers as it doesn't have to generate the whole page on every request
reduce traffic on clients and servers (no need to reload the header-data and/or scripts over and over again)
If you need data from a rendered site, you should either check if the website provides an API which gives you the data you are looking for or use one of the cli-rendering-engines from this answer.

How can I simulate onclick event in python? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a small project where I have to submit a form to a website.
The website is, however, using onclick event to submit the form (using javascript).
How can the onclick event be simulated in python?
Which modules can be used? I have heard about selenium and mechanize modules. But, which module can be used or in case of both, which one is better?
I am new to web scraping and automation.So,it would be very helpful.
Thanks in advance.
Ideally you don't even need to clicks buttons in these kind of cases.
All you need is to see at what webservice does the form sends request when clicked on submit button.
For that open your developer's control in the browser, Go to the Network tab and select 'preserve log'. Now submit the form manually and look for the first xhr GET/POST request sent. It would be POST request 90% of times.
Now when you select that request in the request parameters it would show the values that you entered while submitting the form. Bingo!!
Now all you need to do is mimic this request with relevant request headers and parameters in your python code using requests. And Wooshh!!
Hope it helps..
There is no silver bullet in simulating onclick events on a web page. It is pretty much use-case specific, but here are some points and guidelines.
In general, there are two approaches:
use browser developer tools, open the network tab, make the click and see what request is being sent to the server. Then, simulate this request in Python, with, for example, requests.
use selenium which would fire up a real browser where you would find the specific element and click via .click() method
mechanize would not execute/trigger the onclick function, because executing onclick requires executing javascript which mechanize cannot do.

Javascript continuing after another page is loaded [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to know how (if even possible) to keep my javascript running after i've continued to the next page.
My situation:
Javascript clicks next button.
I'm now on a new page.
But the javascript stops running and all my functions/variables are gone.
I want to be able to push the button with javascript and then continue running the code that comes after that .click() part.
If its not possible can you maybe suggest a way to do this programmaticly?
No.
Once you leave the page, any JavaScript running on that page will also stop running.
You have two options.
Store any variables or settings you need using cookies, and continue running the same script on the next page.
Don't actually leave the page. You can use AJAX to load new information on the page, or perhaps change part of the page content using an IFRAME while the host page continues to load.
As #mike-edwards has said in the comments, you need a single page app.
You can use frameworks like AngularJS or Knockout.js to make your life easier.
As you said, whenever a new page loads in the browser, all your variables etc from the previous page will be lost. The only way to preserve your variables is to not change the page. You can do this using these frameworks and the HTML5 History infrastructure.
With AngularJS, history support comes out of the box. As far as I know, Knockout.js does not have history API support so you would need to use another JS plug-in like Davis.js for that.

Get progress of next page loading? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there a way to get the percentage of page loaded after a user clicks a link or a submit button on a form?
When the user submits a form, an overlay is presented while the next page loads next. This can take a few seconds or minutes while the info is being processed. Is there a way to get the progress of the of the loading of the page being redirected to?.
I'm assuming ajax is used.
The most basic form of progress you can get in a webpage is via the onreadystatechange event. The ajax response object will have a code telling you the load status of the page. More info here.
This isn't really helpful though, as the bulk of the operation will occur on readystate == 3, so if you show 20% * readystate you'll almost immediately get to 80% and then have to wait for the page to actually get here.
A better (and slightly more complicated way), is to set an http header called "Content-Length" to the total amount of bytes being sent, and then use the xhr onProgress event. in this event, your data object will have two properties: total, which is the amount of bytes set in the header; and loaded, or the amount of bytes received. from then on it's quite simple to make a progress indicator. More info here
if you want help with your specific code, upload it and I'll be happy to edit this answer and add real code that fits in with yours.

asp.net mvc a grid of results with close buttons [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Currently converting an old asp.net web forms page into a asp.net mvc version, and a little stuck on something that isn't a major deal, but would be a nice to have.
When the user logs in, they are taken to a messages page at /Alerts. They can close individual messages by clicking the x's, and then if they close all the message they are moved onto another page automatically.
The original site did postbacks, so the URL stayed the same. In my new version, I planned to make the x button a link, that went to /Alerts/Confirm/xx where xx is the id. The problem is, after processing, the address bar stays on that url, whereas I'd like to leave it on /Alerts
The four solutions appear to be either:
1) using AJAX to do the processing;
2) a redirect back to /Alerts after processing;
3) replacing all the X links with a submit button, and using javascript to pass a different ID depending on which message is being acknowledged, so that I can change the Confirm method to an HttpPost-accepting Index method?
4) URL Rewrites? (not sure about this, just thought of as I wrote this)
Or am I missing something obvious that would do what I'm trying to achieve?
I agree with #1 and use Jquery to do it.
Or you could show/hide those messages using Jquery .show() .hide(). So, they would always be there, just hidden. When they hit refresh they would show again.
You can also use some sort of notification plugin for jquery, there are many available just google for it, this page has about 6 examples, it is a bit old but you can get an idea.

Categories