Scripts to automate buying clothes online won't work

53 views
Skip to first unread message

long.v...@gmail.com

unread,
Jun 2, 2017, 12:19:02 AM6/2/17
to CasperJS
Hi guys. I'm trying to write some scripts that automatically login some targeted websites, choose the specified size, color... and add it to the cart. I use this.capture() after every step and it shows that the items were added to my cart. But the thing is when I login my account using actual browser there is nothing there. Anyone knows why this is the case? Thanks in advance!

Ken

unread,
Jun 2, 2017, 12:47:46 AM6/2/17
to CasperJS
The only thing I can think of is the website that you are automating somehow stores the shopping cart information as cookies or dependent on browser cookie, instead of storing that information purely on their server for your user account. Is there a save option to save your selection? Another possibility I can think of is some websites intentionally have special code to handle automated / invisible browsers. So it may be the website trying to be funny and not working to save your selection after you quit the automation.

Possible solutions is modifying user-agent or add steps to behave like a real browser. Such as some random delay between steps. But if it is related to cookie, then maybe can explore some other solution using real browsers such as Chrome (through Selenium etc + Xvbf). I have tried Firefox with SlimerJS cookie by using profile but doesn't seem to work well for me.

long.v...@gmail.com

unread,
Jun 2, 2017, 1:42:24 AM6/2/17
to CasperJS
Hi Ken. I've managed to fix the bug. It was something related to the buggy casper.then() function that I need to put loadInProgress=true before any click. 
However, I can't access nike.com with casper. When I try to open 'http://www.nike.com/us/en_us/' I get a HTTP 403 Access Denied. Do you know how to fix it?
Thanks !

Ken Soh | Tebel

unread,
Jun 2, 2017, 1:51:17 AM6/2/17
to casp...@googlegroups.com
Works for me with following script. Is able to visit website. I am able able to capture screenshot of webpage. Maybe it could be Nike website blocking access to certain IP addresses? I'm accessing from Singapore. If you suspect is proxy issue can consider using phantom.setProxy() example in this issue - https://github.com/casperjs/casperjs/issues/1445

OUTPUT - http://www.nike.com/us/en_us/ - Nike. Just Do It. Nike.com



SCRIPT

var casper = require('casper').create();

casper.options.logLevel = 'debug';


casper.options.viewportSize = {

width: 1366,

height: 768

};


casper.options.pageSettings = {

loadImages: true,

loadPlugins: true,

webSecurityEnabled: true,

ignoreSslErrors: false,

localToRemoteUrlAccessEnabled: false

};


casper.start('http://www.nike.com/us/en_us/', function() {

this.echo('http://www.nike.com/us/en_us/' + ' - ' + this.getTitle() + '\n');});


casper.run();



Kind Regards,

--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
 
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
---
You received this message because you are subscribed to a topic in the Google Groups "CasperJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/casperjs/UyWXl_rRTEE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to casperjs+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

long.v...@gmail.com

unread,
Jun 2, 2017, 2:27:13 AM6/2/17
to CasperJS
Hmm. I'm accessing it from US. Thank you I'll look into it!


Kind Regards,

To unsubscribe from this group and all its topics, send an email to casperjs+u...@googlegroups.com.

Ken Soh | Tebel

unread,
Jun 2, 2017, 3:08:23 AM6/2/17
to casp...@googlegroups.com
No probs! Interesting case, I haven't come across a situation like that.. I was helping someone on a CasperJS GitHub issue recently, it is a website which blocks traffic outside of US. So I decided to give a miss and not to look further into it.

Kind Regards,

To unsubscribe from this group and all its topics, send an email to casperjs+unsubscribe@googlegroups.com.

Ken Soh | Tebel

unread,
Jun 2, 2017, 3:11:05 AM6/2/17
to casp...@googlegroups.com
Adding on, did it fail the first time you tried? I know that some websites such as Amazon will keep a counter of how many times the automated browser access the website within a time period and blocks access from the IP if the threshold is crossed.


Kind Regards,

long.v...@gmail.com

unread,
Jun 2, 2017, 1:23:36 PM6/2/17
to CasperJS
Yes I haven't been able to access Nike since the first time.

I'm trying to use template literal to embed js expression in function click(xpath..) but I keep getting syntax error: Invalid character: '`'. Do you how to fix this one?

Ken Soh | Tebel

unread,
Jun 2, 2017, 4:12:28 PM6/2/17
to casp...@googlegroups.com
I have not come across ember js or use it before with CasperJS. If you are asking about using XPath, first define a XPath helper with - 

var x = require('casper').selectXPath;


After that you can access the element by the example below or other variations of XPath -


this.click(x('//*[@id="username"]'));



Kind Regards,

To unsubscribe from this group and all its topics, send an email to casperjs+unsubscribe@googlegroups.com.
Message has been deleted

long.v...@gmail.com

unread,
Jun 3, 2017, 11:08:03 AM6/3/17
to CasperJS
Yes I'm using xpath but here i'm trying to embed js expression inside xpath like 
x("//*[@id=${username}]"

but it just doesn't work. I found another way around it by constructing a string and pass it inside the function.

Ken Soh | Tebel

unread,
Jun 3, 2017, 4:40:47 PM6/3/17
to casp...@googlegroups.com
Not sure if CasperJS supports using Embed and template liberal directly. If it does, and ${username} is considered a variable to it, then something like below can be used to build the full XPath.

Since you can construct as string, probably something like below can be tested to build XPath. Just replicate the steps you construct a string directly into below format. There has to be quotes enclosing the string. If double quotes are used outside, then inside you can use single quotes without escaping.

x("//*[id='" + ${username} + "']")


Kind Regards,

On 3 June 2017 at 23:02, <long.v...@gmail.com> wrote:
Yes but I want to use template literal to embed that username in the xpath like:
x("//*[id=${username}]")
Enter code here...






On Friday, June 2, 2017 at 2:12:28 PM UTC-6, Ken wrote:

long.v...@gmail.com

unread,
Jun 3, 2017, 11:28:07 PM6/3/17
to CasperJS
I did some Google research and they said it depends on the headless browser version. 

long.v...@gmail.com

unread,
Jun 3, 2017, 11:29:33 PM6/3/17
to CasperJS
Also I'm trying to login https://www.zara.com/us/ but I keep getting http 412 precondition failed. Do you know the solution to this problem ? I did some google but it didn't show up anything related.

long.v...@gmail.com

unread,
Jun 3, 2017, 11:31:51 PM6/3/17
to CasperJS
I guess it has something to do with the client certificate? But I'm not sure how to fix it

Ken Soh | Tebel

unread,
Jun 4, 2017, 1:22:09 AM6/4/17
to casp...@googlegroups.com
If it is related to SSL certificate, you can try something like below just after you create casper object. It is the least secure settings and may help SSL certificate-related issues.

casper.options.pageSettings = {

webSecurityEnabled: false,

ignoreSslErrors: true,

localToRemoteUrlAccessEnabled: true

};




Kind Regards,

To unsubscribe from this group and all its topics, send an email to casperjs+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages