-
Notifications
You must be signed in to change notification settings - Fork 1
/
crawl.py
62 lines (46 loc) · 1.69 KB
/
crawl.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
60
61
62
#if you skid this...
import re
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin, urlparse
def crawl_url(url, target_patterns):
try:
response = requests.get(url)
response.raise_for_status()
soup = BeautifulSoup(response.content, 'html.parser')
links = soup.find_all('a', href=True)
subdomains = set()
urls = set()
target_pages = set()
for link in links:
href = link['href']
parsed_url = urlparse(href)
if parsed_url.scheme and parsed_url.netloc:
subdomain = re.sub(r'^www\.', '', parsed_url.netloc.split('.')[0])
subdomains.add(subdomain)
urls.add(href)
if any(pattern in href for pattern in target_patterns):
target_pages.add(href)
return list(subdomains), list(urls), list(target_pages)
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return [], [], []
if __name__ == "__main__":
# Replace 'LINK HERE' with the URL you want to crawl
base_url = 'LINK HERE'
target_patterns = ['/download']
subdomains, urls, target_pages = crawl_url(base_url, target_patterns)
if subdomains:
print("Subdomains found:")
for subdomain in subdomains:
print(subdomain)
if urls:
print("\nURLs found:")
for url in urls:
print(url)
if target_pages:
print("\nTarget pages found:")
for target_page in target_pages:
print(target_page)
else:
print("No subdomains, URLs, or target pages found.")