Skip to content

Instantly share code, notes, and snippets.

@scrubmx
Created April 12, 2019 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scrubmx/86fa56193a200848f7fb432a3408546e to your computer and use it in GitHub Desktop.
Save scrubmx/86fa56193a200848f7fb432a3408546e to your computer and use it in GitHub Desktop.
Conekta Scraper
pip install selenium
#!/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('raguilar@datacreativa.rocks', 'secret')
emails = [
'testversion3@mediakey.com.mx',
'carlosav98@outlook.com',
'testversion1@mediakey.com.mx',
'paydiyispi@desoz.com',
]
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