Input in Selenium with Python

Asked

Viewed 22 times

-3

I started studying the tool selenium there are exactly 2 hours and I was wondering if it is possible to do the following:
Run a program and it ask me the site I want to access, paste the link and the program open the site on the link I typed, is possible?

1 answer

0

It is possible yes, to start remember to download, according to the browser version, the chromedriver if you are using the browser Google Chrome or the geckodriver if you are using the browser Firefox, and leave the executable in the same path as your execution file.

Start your code by importing the module selenium:

from selenium import webdriver

To define which site you will open, create a vaiável that will receive a input:

url = str(input('Site: '))

Once done, create the variable driver which will receive the browser:

driver = webdriver.Chrome()

Finally, add the method .get() in the variable driver putting the variable url as a parameter to access the site:

driver.get(url)

The whole code goes like this:

from selenium import webdriver

url = str(input('Site: '))
driver = webdriver.Chrome()
driver.get(url)

To learn more about the module Selenium, Click here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.