-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetchURL.py
More file actions
31 lines (23 loc) · 910 Bytes
/
fetchURL.py
File metadata and controls
31 lines (23 loc) · 910 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from urllib.parse import urljoin
import time
class URLFetcher:
def __init__(self, base_url):
self.base_url = base_url
self.driver = webdriver.Chrome()
def fetch_urls(self):
try:
self.driver.get(self.base_url)
time.sleep(5)
links = self.driver.find_elements(By.TAG_NAME, 'a')
urls = [urljoin(self.base_url, link.get_attribute('href')) for link in links if link.get_attribute('href')]
print(f"Found {len(urls)} URLs")
return urls
except Exception as e:
print(f"Error fetching URLs: {e}")
return []
finally:
self.driver.quit()