Building web bots with selenium 05-24-2016, 07:37 PM
#1
Selenium is a great framework that integrates with chrome (on linux) and firefox. It gives users easy access to DOM traversal tools like finding elements via css selectors, xpath, id, and a myriad of other methods.
The module also has the capacity to send special keys like enter and is able to click on elements.
Below is a quick demonstration of a bot that logs into facebook.
Originally, I was going to make it a spambot, but that's a lot of code for a simple demonstration, and you guys can figure it out for yourselves
To install, simply run (on linux, add sudo obviously):
All this said, Selenium is pretty cool, but super heavyweight and shouldn't be used for retrieving html data. Use the requests module for that.
The module also has the capacity to send special keys like enter and is able to click on elements.
Below is a quick demonstration of a bot that logs into facebook.
Code:
from selenium import webdriver,keys
from sys import argv
driver=webdriver.Firefox() # initialize the driver
driver.get('https://www.facebook.com/') # go to the facebook login page
# assign the 'username' variable to the DOM element with id 'email'
username=driver.get_element_by_id('email')
# assign the 'password' variable to the DOM element with id 'pass'
password=driver.get_element_by_id('pass')
# enter credentials (supplied by script arguments)
username.send_keys(argv[1])
password.send_keys(argv[2])
# find and click the login button
driver.get_element_by_id('u_0_w').click()Originally, I was going to make it a spambot, but that's a lot of code for a simple demonstration, and you guys can figure it out for yourselves

To install, simply run (on linux, add sudo obviously):
Code:
// python 2
pip install selenium
// python 3
pip3 install seleniumAll this said, Selenium is pretty cool, but super heavyweight and shouldn't be used for retrieving html data. Use the requests module for that.
It's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.















![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)




![[Image: pBD38Xq.png]](http://i.imgur.com/pBD38Xq.png)



