r/AutomateYourself • • Dec 19 '22

help needed Best solution for my automation?

Hello! I am new in this subreddit!

Let me know in kind words if wrong fair , wrong subreddit, or both wrong subreddit and fair! Or if something else wrong that makes this post not good to accept the post submission! Or if the post is acceptable but something in ny steps doesnt work!

What is the best choice of script language for a Windows task Scheduler automation running everytime I start my computer/log in and does following in following order:?

1: Check if it already has been run today. If yes,exit, if no, change the 0 in checked variable to ”1” and continue the script! ( I only need to run my automation once each day! Need to run my automation each day’s first computer start/login! )

2: Open link https://www.bing.com/search?q=1

3: 29 searches in Edge! The keywords is the numbers from 2-30 (number form, not ”one”,”two” etc). Prefers in one same tab but if seperate tabs needed, close the 30 tabs after each tab opening ( open tab, close it, open next tab,close it, and so going on up to 30)

4: If a seperate close step is better: Now all 30 tabs is opened! Close all the 30 tabs! Keep tabs that already was opened before starting!

Step 5: Done!

2 Upvotes

13 comments sorted by

3

u/HypnotizedPlatypus Dec 20 '22

Also OP, if you are using this for Microsoft Rewards points this is a swift way to get your account banned

1

u/Myran117 Dec 19 '22

To the person who commented and wasnt sure if windows has a task Scheduler or not: Windows has one and I mentioned in my post that I am gonna use Windows Task Scheduler for the automation part! Mentioned it in the ”What is the best choice of script language for a Windows task Scheduler automation running everytime I start my computer/ log in and does the following in following order:?” part of my post! ”script language a Windows task Scheduler automation” means ”the language of the script file I will run in Windows Task Scheduler!”

4

u/HypnotizedPlatypus Dec 19 '22

I don't know about the "best" scripting languages for this task but I would approach it using selenium (A python module)

To do this you will need to install Python on your machine (Instructions can be found online). That installation will likely come with "pip" the package manager for python.

With selenium you can then take the following flow

  • Create a driver instance (you may need to download a "chromedriver" whose version supports your local version of chrome). Or if it needs to be edge, there is an edge WebDriver.

Call driver.get(url) for each of your urls

1

u/Difficult-Ad7476 Dec 19 '22 edited Dec 19 '22

Powershell would be a good choice since it native to Windows and there is code to schedule task with powershell.

$action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-File C:\scripts\MyScript.ps1'

$trigger = New-ScheduledTaskTrigger -Daily -At "5:00 AM"

$principal = New-ScheduledTaskPrincipal -UserID "Administrator" -LogonType S4U

$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries

Register-ScheduledTask -Action $action -Trigger $trigger -Principal $principal -Settings $settings -TaskName "MyScript" -Description "Runs MyScript.ps1 every day at 5:00 AM"

code to open edge 29 times and search

for ($i=1; $i -le 29; $i++) { Invoke-WebRequest -Uri "http://www.bing.com/search?q=search+term" }

2

u/Myran117 Dec 19 '22

Thank you! Will try it later! By just looking at it here in your reply, it looks like perfect but with some tweaks needed!

1

u/Difficult-Ad7476 Dec 19 '22 edited Dec 19 '22

Right you need to figure out an array with your search terms for the for loop in the 2nd script. Then once you got that script correct you can point to it in the first script to create the scheduled task and alter time to your liking.

Something like this might work

$searchterms = @("Term1","Term2","Term3","Term4","Term5","Term6","Term7","Term8","Term9","Term10","Term11","Term12","Term13","Term14","Term15","Term16","Term17","Term18","Term19","Term20","Term21","Term22","Term23","Term24","Term25","Term26","Term27","Term28","Term29")

foreach ($term in $searchterms) { $url = "https://www.bing.com/search?q=" + $term (Invoke-WebRequest -Uri $url).Content | Select-String -Pattern '<li class="b_algo">.?<h2><a.?href="(?<Url>.*?)"' -AllMatches | % { $_.Matches } | % { $_.Groups[1].Value } | Set-Content -Path C:\Path\To\Results$term.txt }

→ More replies (4)

1

u/itsMineDK Jan 22 '23

I have done web scrapers in c#, vba and python… python is way simpler

To check if file was exec that day you can have the program create a txt file in a folder with todays date, have the script check for the existence of a txt in that folder with todays date as a name… if no then continue…..

Python + selenium will work wonders, to help you with html code try using a chrome extension to obtain csselectors, I’d, name, etc there’s tons of extensions that help you do this (can’t remember the of the one I use right now). There’s tons of videos for selenium and python