Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clicking a button automatically in a web browser with python

Tags:

python

bots

Sort of like a bot, i have already checked out some sites such as pyjamas and scrapy, I know how to print data of websites, but still dont know how to interact with buttons. Can somebody help me with some demonstarative code?

Lets say i have a form

<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>

how do i identify the button to be clicked, so that python can click it for me? If anybody knows any sites with demonstarative code, i would be very pleased.

like image 907
Bartlomiej Lewandowski Avatar asked Apr 17 '11 11:04

Bartlomiej Lewandowski


People also ask

How do you click a button in web scraping Python?

We can click a button with Selenium webdriver in Python using the click method. First, we have to identify the button to be clicked with the help of any locators like id, name, class, xpath, tagname or css. Then we have to apply the click method on it.


2 Answers

You can use mechanize for that. It provides an easy way for interacting with websites.

like image 151
utdemir Avatar answered Sep 30 '22 20:09

utdemir


If you’re looking to really simulate a browser, you might want to look at Selenium, which allows you to control a real web browser.

If the website you’re looking to interface with uses a lot of JavaScript (e.g. onclick handlers), it can be very handy.

like image 31
Paul D. Waite Avatar answered Sep 30 '22 19:09

Paul D. Waite