Created
April 12, 2019 22:42
-
-
Save scrubmx/86fa56193a200848f7fb432a3408546e to your computer and use it in GitHub Desktop.
Conekta Scraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install selenium |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import re as regex | |
from time import sleep | |
from getpass import getpass | |
from selenium import webdriver | |
from __future__ import print_function | |
def login(username, password): | |
browser.get('https://auth.conekta.com/login') | |
browser.find_element_by_id('user_email').send_keys(username) | |
browser.find_element_by_id('user_password').send_keys(password) | |
getpass('=> Press enter after you are done logging in\n') | |
def get_customer_id(link): | |
href = link.get_attribute('href') | |
matches = regex.search(r'/?customers/(cus_\w+)/?$', href) | |
return matches.group(1) if matches else '' | |
def get_customer_information(email): | |
browser.implicitly_wait(5) | |
browser.get('https://admin.conekta.com/customers?search={query}'.format(query=email)) | |
try: | |
customer_links = browser.find_elements_by_xpath('//a[contains(@href,"/customers/cus_")]') | |
for link in customer_links: | |
if (link.get_attribute('text').lower() == email.lower()): | |
customer_id = get_customer_id(link) | |
print('{email}, {id}'.format(email=email, id=customer_id)) | |
except Exception as exception: | |
print(email, str(exception)) | |
if __name__ == '__main__': | |
print('=> Opening web browser...') | |
browser = webdriver.Chrome() | |
print('=> Logging in to the website...') | |
login('[email protected]', 'secret') | |
emails = [ | |
'[email protected]', | |
'[email protected]', | |
'[email protected]', | |
'[email protected]', | |
] | |
print('email,customer_id') | |
for email in emails: get_customer_information(email) | |
print('\n=> Closing web browser...') | |
browser.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment