-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLextractor.py
More file actions
39 lines (29 loc) · 1.08 KB
/
HTMLextractor.py
File metadata and controls
39 lines (29 loc) · 1.08 KB
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
import requests
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
class HTMLExtractor:
def __init__(self):
self.driver = None
def setup_driver(self, url):
# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument("--headless") # Run in headless mode
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
# Initialize the WebDriver
self.driver = webdriver.Chrome()
# Navigate to the URL
self.driver.get(url)
def extract_html(self):
# Return the full HTML content of the page
return self.driver.page_source
def get_html(self, url):
# Set up the driver and navigate to the URL
self.setup_driver(url)
# Extract the HTML content
html_content = self.extract_html()
# Close the browser
self.driver.quit()
return html_content