-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_crawler.py
35 lines (29 loc) · 1.06 KB
/
run_crawler.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
"""
This file initializes the web browser and runs the web crawler.
"""
import web_crawler
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
def setup_browser():
"""
Configures and initializes a Firefox browser instance with appropriate settings.
"""
binary = FirefoxBinary(r'C:\Program Files\Mozilla Firefox\firefox.exe')
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("pdfjs.disabled", True)
return webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)
def run_crawler():
"""
Initializes the browser and executes the crawling function.
"""
browser = setup_browser()
try:
# Start crawling
Crawler.crawling_in_my_skin(browser)
except Exception as e:
print(f"An error occurred during crawling: {e}")
finally:
# Ensure browser is closed after crawling
browser.quit()