Biks 9 Posted January 4, 2016 Report Share Posted January 4, 2016 I need to change my user agent frequently because Ubot crashes if I don't. I want to do change it after every sequence of events. I'm trying to EVAL an incrementing variable - if it's odd, change to Chrome. If it's even, change to Safari. I came up with this: ui stat monitor("Useragent #:",#useragent)set(#useragent,1,"Global")loop(5) { if(#useragent = $eval("^(\\s*\\d*[13579]\\s*,)*(\\s*\\d*[13579]\\s*)$")) { then { set user agent("Chrome") alert("ODD") } else { set user agent("Safari") alert("EVEN") } } increment(#useragent)} This doesn't work. Is there an easier way to change a user agent? Quote Link to post Share on other sites
pash 504 Posted January 4, 2016 Report Share Posted January 4, 2016 check user agent use http://whatsmyuseragent.com/ set user agent("Chrome")navigate("http://whatsmyuseragent.com/","Wait")pause scriptset user agent("Safari")navigate("http://whatsmyuseragent.com/","Wait") Quote Link to post Share on other sites
pash 504 Posted January 4, 2016 Report Share Posted January 4, 2016 or set user agent("Chrome") navigate("http://user-agent.me/","Wait") pause script set user agent("Safari") navigate("http://user-agent.me/","Wait") Quote Link to post Share on other sites
pash 504 Posted January 4, 2016 Report Share Posted January 4, 2016 or set user agent("Chrome") load html("<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js\"></script> <input type=\"text\" id=\"UserAgent\"> <script>$(\'#UserAgent\').val(navigator.userAgent);</script>") set(#user agent,$eval("var x = document.getElementById(\'UserAgent\').value = navigator.userAgent; x;"),"Global") alert(#user agent) Quote Link to post Share on other sites
Biks 9 Posted January 4, 2016 Author Report Share Posted January 4, 2016 Thanks for looking at this Pash. I know how to set a user agent, that's easy. (I already have that in my example.) I have pauses and alerts in my example, just so I can see what's going on. Ultimately I don't want them in there. They're for testing purposes only. I want it to: (start the loop) 1. Set user agent to Chrome.2. do it's thing (loop)3. Set user agent to Safari3. do it's thing (loop)4. etc. forever. Do this with no input from me. Quote Link to post Share on other sites
pash 504 Posted January 4, 2016 Report Share Posted January 4, 2016 Thanks for looking at this Pash. I know how to set a user agent, that's easy. (I already have that in my example.) I have pauses and alerts in my example, just so I can see what's going on. Ultimately I don't want them in there. They're for testing purposes only. I want it to: (start the loop) 1. Set user agent to Chrome.2. do it's thing (loop)3. Set user agent to Safari3. do it's thing (loop)4. etc. forever. Do this with no input from me.try. set(#Check,$true,"Global") loop(5) { if(#Check) { then { set user agent("Chrome") navigate("http://user-agent.me/","Wait") wait for browser event("Everything Loaded","") wait(1) set(#Check,$false,"Global") } else { set user agent("Safari") navigate("http://user-agent.me/","Wait") wait for browser event("Everything Loaded","") wait(1) set(#Check,$true,"Global") } } } Quote Link to post Share on other sites
Biks 9 Posted January 4, 2016 Author Report Share Posted January 4, 2016 Woo hoo! That did it! I've never used the TRUE/FALSE type variable - till now. See what happens when you have a Photoshop expert trying to do programming? :-) Quote Link to post Share on other sites
web4you.pro 3 Posted January 4, 2016 Report Share Posted January 4, 2016 (edited) You can optimization code: Conditions:set(#useragent,"Chrome","Global")set(#useragent,"Safari","Global") Loopset user agent(#useragent)navigate("http://user-agent.me/","Wait") Edited January 4, 2016 by web4you.pro Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.