Learn to Code via Tutorials on Repl.it!

← Back to all posts
Lets make a python bot :) part 1 for beginners :))
generationXcode (530)

😎💻 bots r cool :)

Ok guys this is the second time I'm writing this!!!
We are making a bot today with python. This aint no discord bot. Nonono! this is a web bot (or whatever thats called)

This tutorial will be shorter than the last because even I dont have that large of an attention span in a tutorial and I want people to learn from what I make

Our bot will search up in repl answers and get an answer(the first) for our question that we type in our bot

the code

Lets get our hands dirty with some code now


we need selenium as the webdriver library for this project.
First you need to install it by writing this in your cmd/terminal:

python -m pip install selenium


py -m pip install selenium

now write this in your file:

from selenium import webdriver

get the question

Now we need the question that the user wants to search ->

question=input("what do you want an answer for?")

Thats how python gets inputs.
Now that we have that lets get our driver


First download firsfox cus thats what we are using here and trust me you will thank me (even tho I'm using chrome while writing this)

Now get the gecko driver for firefox (what we need for the automation) from here:

Now get the path of the driver (gecko driver) the web driver that you just downloaded and put this in your code:

driver = webdriver.Firefox(executable_path = '[path]')

My path was something like this : driver = webdriver.Firefox(executable_path = '[path]/geckodriver-v0.26.0-win64/geckodriver.exe')

Ok now!

get the link!!!

Here we can actually search something on replit by entering a link! like this :

we are going to take advantage of this hahaha to do that we can easily just write this:


So done now!

clicking on the question to load it in

Now I searched up al lot of these answers and I got a css selector. I have it ready for you in this code so you need not do the work but you should know that its quite easy to do from the devtools :)

here is the code:

driver.execute_script("document.querySelector('div.posts-feed-item:nth-child(1) > div:nth-child(1) > a:nth-child(1) > div:nth-child(1)').click()")

Now thats all for this lesson. here is all the code together:

from selenium import webdriver
question=input("what do you want an answer for?")
driver = webdriver.Firefox(executable_path = '[path]/geckodriver-v0.26.0-win64/geckodriver.exe')
driver.execute_script("document.querySelector('div.posts-feed-item:nth-child(1) > div:nth-child(1) > a:nth-child(1) > div:nth-child(1)').click()")

Now this is a start of what (hopefully) will be a series. I need your inputs from the comments section on what to do now :)

also dont try this on replit do it locally because it doesnt work on replit...

Thats it for today and happy coding

^ that's me right there, no a bit to the side now a bit right - yes! Right there in the middle!

generationXcode (530)

@mkhoi @Jakman @techgeek680 @TheForArkLD @DynamicSquid the next part of this tutorial is out at https://repl.it/talk/learn/lets-make-a-bot-python-series-part-2-TIC-TAC-TOE/43409 if you missed it. I'm creating the third part which is supposed to an epic end to the bot series :) But cant make any promises. The code can go south at any moment...

AnasAAlam (0)

can i run this in replit.com

generationXcode (530)

thinking of releasing one on reinforcement learning soon...

generationXcode (530)

@generationXcode or maybe that new language I just learnt...

HahaYes (1869)

@generationXcode Oh no, you are #1 on tutorials. Congrats! (I guess time to make a new C++ tutorial now)

generationXcode (530)

@HahaYes really? I am so happy!! can you link ur c++ tutorial also I want to learn. :)

HahaYes (1869)

@generationXcode lol just check the tutorial section

generationXcode (530)

@HahaYes I no want to scroll to down to ur first but Oki

HahaYes (1869)

@generationXcode what I'm first again? hmmm

generationXcode (530)

@generationXcode someone else looking at this thread will be so confused lmao

generationXcode (530)

@HahaYes cool :) upvote mine then lmao