diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 44fe52b..8f79699 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # EmailPhoneParse Python Script to Parse *Phone #* and *E-mails* from Websites + +For Run This Install Following Module By Those Command: +pip install bs4 +pip install requests diff --git a/emailphonescraping.py b/emailphonescraping.py index c1e44b7..aecefd4 100644 --- a/emailphonescraping.py +++ b/emailphonescraping.py @@ -9,36 +9,49 @@ from bs4 import BeautifulSoup import re -from urllib.request import urlopen +import requests -f = urlopen('http://www.bc.edu/a-z/directories/contact/quicknos.html') +web_name=input("Please Enter The Name Of Website:") +print("*****************************************************************") +print("Please Choose The Option:") +print("1) Find All Emails") +print("2) Find All Phone Numbers") +ch=input("Enter Your choice:") -s = BeautifulSoup(f, 'html.parser') +f = requests.get(web_name) + +s = BeautifulSoup(f.text, 'html.parser') s = s.get_text() -phone = re.findall(r"((?:\d{3}|\(\d{3}\))?(?:\s|-|\.)?\d{3}(?:\s|-|\.)\d{4})",s) -emails = re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,3}",s) +if ch=="1": + emails = re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,3}",s) + print('-----------------------------------------------------') + print() + + if len(emails) == 0: + print("Sorry, no email address found.") + print('------------') + print() + else: + count = 1 + for item in emails: + print(count, ' email address(es) found : ', item) + count += 1 +elif ch=="2": + phone = re.findall(r"((?:\d{3}|\(\d{3}\))?(?:\s|-|\.)?\d{3}(?:\s|-|\.)\d{4})",s) + + if len(phone) == 0: + print ("Sorry, no phone number found.") + + print('------------') + print () + else : + print('-----------------------------------------------------') + count = 1 + for item in phone: + print ( count, ' phone number(s) found : ',item ) + count += 1 -if len(phone) == 0: - print ("Sorry, no phone number found.") - print('------------') - print () -else : - count = 1 - for item in phone: - print ( count, ' phone number(s) found : ',item ) - count += 1 -print('------------') -print() -if len(emails) == 0: - print("Sorry, no email address found.") - print('------------') - print() -else: - count = 1 - for item in emails: - print(count, ' email address(es) found : ', item) - count += 1