-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeb Scraping Example
More file actions
35 lines (21 loc) · 865 Bytes
/
Web Scraping Example
File metadata and controls
35 lines (21 loc) · 865 Bytes
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
#This example was written for an internal webpage which displays a password which is randomly generated each day
#This script will scrape the page and only display the password
import requests
from bs4 import BeautifulSoup
#URL which contains the randomly generated password
url = 'REDACTED_URL'
print (f"Attempting to reach {url}\n")
try:
#We perform a GET request on the URL
r = requests.get(url)
#We parse the HTML page's content via BeautifulSoup
soup = BeautifulSoup(r.content, 'html.parser')
#We look for the div which contains the password placeholder
pw_ph = soup.find('div', attrs={'id': 'Content'})
#We strip the text from the password placeholder div
pw= pw_ph.text.strip()
#We print the password
print (f"Service is up!")
print (f"{pw}")
except:
print (f"Something went wrong accessing {url}!")