-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenario3.py
31 lines (25 loc) · 876 Bytes
/
scenario3.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
# Import libraries
import requests
from bs4 import BeautifulSoup
# Specify target url
URL = "https://website.com/release/2/"
# Select user agent: https://deviceatlas.com/blog/list-of-user-agent-strings
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246"}
r = requests.get(url=URL, headers=headers)
# print(r.content)
# Parse html content
soup = BeautifulSoup(r.content, 'html5lib')
# print(soup.prettify())
# Extract all urls in <a> tags in a <div> with a specific class
urls = []
# In line 21, modify _class="..." with your desired div class
for data in soup.findAll('div', class_="txt"):
link = data.find('a')
try:
if 'href' in link.attrs:
url = link.get('href')
urls.append(url)
except:
pass
for url in urls:
print(url)