Created
November 14, 2018 21:34
-
-
Save WittmannF/292bf7634adab24445e1006025c039e8 to your computer and use it in GitHub Desktop.
WhatsApp API 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
""" | |
### Implemented Methods | |
- Get contacts from a selected group | |
### Requires | |
- Selenium: `pip install selenium` | |
- ChromeDriver: http://chromedriver.chromium.org/ | |
- After downloading chromedriver, make sure to add in a folder accessible from the PATH | |
### Example of Usage: | |
In [1]: from whatsapp_api import WhatsApp | |
In [2]: wp = WhatsApp() | |
Loading... | |
Please scan the QR Code and enter in the group | |
In [3]: wp.get_contacts() | |
Out[3]: | |
[u'+1... | |
""" | |
from selenium import webdriver | |
from selenium.webdriver.chrome.options import Options | |
# Whatsapp Parameters | |
WP_LINK = 'https://web.whatsapp.com' | |
CONTACTS_XPATH = '//*[@id="main"]/header/div[2]/div[2]/span' | |
class WhatsApp: | |
def __init__(self): | |
self.driver = self._setup_driver(self) | |
self.driver.get(WP_LINK) | |
print("Please scan the QR Code and enter in the group") | |
@staticmethod | |
def _setup_driver(self): | |
print('Loading...') | |
chrome_options = Options() | |
chrome_options.add_argument("disable-infobars") | |
driver = webdriver.Chrome(chrome_options=chrome_options) | |
return driver | |
def get_contacts(self): | |
el = self.driver.find_element_by_xpath(CONTACTS_XPATH) | |
return el.text.split(',') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implemented Methods
Requires
pip install selenium
Example of usage: