how to scrape email addresses from a website using python

Solutions on MaxInterview for how to scrape email addresses from a website using python by the best coders in the world

showing results for - "how to scrape email addresses from a website using python"
Elias
30 Mar 2019
1from extract_emails import EmailExtractor
2from extract_emails.browsers import BrowserInterface
3
4from selenium import webdriver
5from selenium.webdriver.firefox.options import Options
6
7
8class FirefoxBrowser(BrowserInterface):
9    def __init__(self):
10        ff_options = Options()
11        self._driver = webdriver.Firefox(
12            options=ff_options, executable_path="/home/di/geckodriver",
13        )
14
15    def close(self):
16        self._driver.quit()
17
18    def get_page_source(self, url: str) -> str:
19        self._driver.get(url)
20        return self._driver.page_source
21
22
23with FirefoxBrowser() as browser:
24    email_extractor = EmailExtractor("http://www.tomatinos.com/", browser, depth=2)
25    emails = email_extractor.get_emails()
26
27for email in emails:
28    print(email)
29    print(email.as_dict())
30
31# Email(email="bakedincloverdale@gmail.com", source_page="http://www.tomatinos.com/")
32# {'email': 'bakedincloverdale@gmail.com', 'source_page': 'http://www.tomatinos.com/'}
33# Email(email="freshlybakedincloverdale@gmail.com", source_page="http://www.tomatinos.com/")
34# {'email': 'freshlybakedincloverdale@gmail.com', 'source_page': 'http://www.tomatinos.com/'}
35