-3

I have this python code, which accesses a website using the module webbrowser:

 import webbrowser
 webbrowser.open('kahoot.it')

How could I input information into a text box on this website?

  • A text box is usually just a post request. Look at the website's source code or track the request when you manually enter information into the text box (e.g. with chrome's developer tools) to see what information to post. Once you have that, you can use "requests.post()" from "requests" package. – Tim Jan 30 '19 at 21:39

3 Answers3

1

I suggest you use Selenium for that matter.

Here is an example code:

from selenium import webdriver 
from selenium.webdriver.common.keys import Keys

# driver = webdriver.Firefox() # Use this if you prefer Firefox. 
driver = webdriver.Chrome()

driver.get('http://www.google.com/')

search_input = driver.find_elements_by_css_selector('input.gLFyf.gsfi')[0]
search_input.send_keys('some search string' + Keys.RETURN)

You can use Selenium better if you know HTML and CSS well. Knowing Javascript/JQuery may help too.

You need the specific webdriver to run it properly:

GeckoDriver (Firefox)

Chrome

There are other webdrivers available, but one of the previous should be enough for you.

On Windows, you should have the executable on the same folder as your code. On Ubuntu, you should copy the webdriver file to /usr/local/bin/

You can use Selenium not only to input information, but also to a lot of other utilities.

0

I don't think that's doable with the webbrowser module, I suggest you take a look at Selenium

How to use Selenium with Python?

Kays Kadhi
  • 538
  • 6
  • 21
0

Depending on how complex (interactive, reliant on scripts, ...) your activity is, you can use requests or, as others have suggested, selenium.

Requests allows you to send and get basic data from websites, you would probably use this when automatically submitting an order form, querying an API, checking if a page has ben updated, ...

Selenium gives you programmatic control of a "normal" browser, this seems better for you specific use-case.

The webbrowser module is actually only (more or less) able to open a browser. You can use this if you want to open a link from inside your application.

user24343
  • 892
  • 10
  • 19