feat: replace print statements with logging
This commit is contained in:
parent
36a0c0fe60
commit
997ab17dd8
1 changed files with 12 additions and 2 deletions
14
proxy.py
14
proxy.py
|
@ -1,5 +1,6 @@
|
||||||
import time
|
import time
|
||||||
import atexit
|
import atexit
|
||||||
|
import logging
|
||||||
|
|
||||||
from config import get_configs, ScraperConfig
|
from config import get_configs, ScraperConfig
|
||||||
|
|
||||||
|
@ -26,16 +27,20 @@ class Scraper:
|
||||||
use_subprocess=False
|
use_subprocess=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
logger.info("Driver started.")
|
||||||
|
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
if self.driver:
|
if self.driver:
|
||||||
try:
|
try:
|
||||||
self.driver.quit()
|
self.driver.quit()
|
||||||
|
logger.info("Driver closed.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error during cleanup: {e}")
|
logger.error(f"Exception during cleanup: {e}")
|
||||||
finally:
|
finally:
|
||||||
self.driver = None
|
self.driver = None
|
||||||
|
|
||||||
def render_page(self, url):
|
def render_page(self, url):
|
||||||
|
logger.info(f"Fetching {url}...")
|
||||||
self.driver.get(url)
|
self.driver.get(url)
|
||||||
|
|
||||||
WebDriverWait(self.driver, timeout=self.config.wait_time).until(
|
WebDriverWait(self.driver, timeout=self.config.wait_time).until(
|
||||||
|
@ -44,10 +49,14 @@ class Scraper:
|
||||||
|
|
||||||
time.sleep(self.config.wait_time)
|
time.sleep(self.config.wait_time)
|
||||||
|
|
||||||
|
logger.info(f"Fetched {url}.")
|
||||||
|
|
||||||
return self.driver.page_source
|
return self.driver.page_source
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# logging.basicConfig(level=logging.INFO)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
server_config, scraper_config = get_configs()
|
server_config, scraper_config = get_configs()
|
||||||
|
|
||||||
scraper = Scraper(scraper_config)
|
scraper = Scraper(scraper_config)
|
||||||
|
@ -64,7 +73,8 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
html = scraper.render_page(url)
|
html = scraper.render_page(url)
|
||||||
return html
|
return html
|
||||||
|
logger.info(f"Successfully sent {url} to client.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}", 500)
|
logger.error(f"Error sending {url} to client: {e}", 500)
|
||||||
|
|
||||||
app.run(host=server_config.host, port=server_config.port)
|
app.run(host=server_config.host, port=server_config.port)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue