-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_scraper.py
61 lines (28 loc) · 985 Bytes
/
web_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'''
Web Scraping the URLs and Email IDs
'''
import urllib.request
from bs4 import BeautifulSoup
# url to Scrap
wiki = 'https://dlca.logcluster.org/display/public/DLCA/4.1+Nepal+Government+Contact+List'
page = urllib.request.urlopen(wiki)
soup = BeautifulSoup(page, features = 'html.parser')
print('\n\nPage Scrapped !!! \n\n')
print('\n\nTitle of the Page \n\n')
print(soup.title.string)
print('\n\nALL THE URLs IN THE WEB PAGE\n\n')
all_links = soup.find_all('a')
print('Total number of URLs present = ',len(all_links))
print('\n\nLast 5 URLs in the page are : \n')
if len(all_links) > 5 :
last_5 = all_links[len(all_links)-5:]
for url in last_5 :
print(url.get('href'))
emails = []
for url in all_links :
if(str(url.get('href')).find('@') > 0):
emails.append(url.get('href'))
print('\n\nTotal Number of Email IDs Present: ', len(emails))
print('\n\nSome of the emails are: \n\n')
for email in emails[:5]:
print(email)