Tim Großmann
Passionate learner and developer. Studying computer science at the Media University. Looking forward to work with ingenious teams on challenging projects.
with Python and Selenium
@timigrossmann
/timgrossmann
@TimGrossmann
contact.timgrossmann
pip install selenium
from time import sleep
from selenium import webdriver
# starting a new browser session
browser = webdriver.Chrome('./assets/chromedriver')
# navigating to a webpage
browser.get('https://www.instagram.com')
# make sure the browser stays open for 5sec
sleep(5)
# clean exit
browser.close()
# find Log in link
login_elem = browser.find_element_by_xpath(
'//article/div/div/p/a[text()="Log in"]')
# click it
login_elem.click()
# find form inputs and enter data
inputs = browser.find_elements_by_xpath(
'//form/div/input')
ActionChains(browser)\
.move_to_element(inputs[0]).click()\
.send_keys('contacting.john.doe')\
.move_to_element(inputs[1]).click()\
.send_keys('passtheword')\
.perform()
# find Log in button and click it
login_button = browser.find_element_by_xpath(
'//form/span/button[text()="Log in"]')
ActionChains(browser)\
.move_to_element(login_button)\
.click().perform()
from selenium.webdriver.common.keys import Keys
# find the body element to send keys to
body_elem = browser.find_element_by_tag_name('body')
# move up and down to load new images
for _ in range(3):
body_elem.send_keys(Keys.END)
sleep(2)
body_elem.send_keys(Keys.HOME)
sleep(2)
# find all the heart links
hearts = browser.find_elements_by_xpath(
'//a[contains(@class, "_tk4ba _1tv0k")]')
# click all the heart links
for i, heart in enumerate(hearts):
print('{}/{}'.format(i, len(hearts)))
heart.click()
sleep(2)
class InstaLoginPage:
def __init__(self, browser):
"""init all the wrapper here"""
self.browser = browser
self.userbox = browser.find_element_by_xpath('...')
self.pw_box = browser.find_element_by_xpath('...')
self.login_button = browser.find_element_by_xpath('...')
def login(self, username, password):
"""Login user with username and pw"""
ActionChains(self.browser)\
.move_to_element(self.userbox)\
.click\
.send_keys(username)\
.move_to_element(self.pw_box)\
.click\
.send_keys(password)\
.move_to_element(self.login_button)\
.click()
# return instance of the following page
return InstaFeedPage(self.browser)
Don't like keywords
Ignore users
Ignoring restrictions
Restrictions
Clarifai - Smart image filtering
Emoji Support
Limit by followers
Works on a Server
Docker support
Clarifai -comments based on image tags
Works without API
Detailed documentation
from instapy import InstaPy
InstaPy(username='EuroPython', password='Rocks!')\
.login()\
.set_upper_follower_count(limit = 2500) \
.set_do_comment(True, percentage=10) \
.set_do_follow(True, percentage=10) \
.set_comments(['Cool!', 'Awesome!', 'Nice!']) \
.set_dont_include(['myFriend', 'myOtherFriend']) \
.set_dont_like('NSFW', 'naked') \
.like_by_tags(['nature', 'cat'], amount=100) \
.end()
@timigrossmann
/timgrossmann
/@TimGrossmann
contact.timgrossmann
By Tim Großmann
Passionate learner and developer. Studying computer science at the Media University. Looking forward to work with ingenious teams on challenging projects.