Skip to content

Commit e477a44

Browse files
authored
Merge pull request #631 from ScrapeGraphAI/627-PIL-import-error
fix(ScreenShotScraper): static import of optional dependencies
2 parents 16ab1bf + 52fe441 commit e477a44

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ more-browser-options = [
9494
screenshot_scraper = [
9595
"surya-ocr>=0.5.0; python_version >= '3.10'",
9696
"matplotlib>=3.7.2; python_version >= '3.10'",
97-
"ipywidgets>=8.1.0; python_version >= '3.10'"
97+
"ipywidgets>=8.1.0; python_version >= '3.10'",
98+
"pillow>=10.4.0",
9899
]
99100

100101
[build-system]

requirements-dev.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ idna==3.7
161161
# via yarl
162162
imagesize==1.4.1
163163
# via sphinx
164+
importlib-metadata==8.4.0
165+
# via sphinx
166+
importlib-resources==6.4.4
167+
# via matplotlib
164168
iniconfig==2.0.0
165169
# via pytest
166170
isort==5.13.2
@@ -450,8 +454,10 @@ typing-extensions==4.12.2
450454
# via pydantic
451455
# via pydantic-core
452456
# via pyee
457+
# via pylint
453458
# via sf-hamilton
454459
# via sqlalchemy
460+
# via starlette
455461
# via streamlit
456462
# via typing-inspect
457463
# via uvicorn
@@ -471,3 +477,6 @@ uvicorn==0.30.5
471477
# via burr
472478
yarl==1.9.4
473479
# via aiohttp
480+
zipp==3.20.1
481+
# via importlib-metadata
482+
# via importlib-resources

scrapegraphai/utils/screenshot_scraping/screenshot_preparation.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
import asyncio
55
from io import BytesIO
6-
from PIL import Image, ImageGrab
76
from playwright.async_api import async_playwright
87
import numpy as np
98
from io import BytesIO
@@ -18,6 +17,10 @@ async def take_screenshot(url: str, save_path: str = None, quality: int = 100):
1817
Returns:
1918
PIL.Image: The screenshot of the webpage as a PIL Image object.
2019
"""
20+
try:
21+
from PIL import Image
22+
except:
23+
raise ImportError("The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[screenshot_scraper]`.")
2124

2225
async with async_playwright() as p:
2326
browser = await p.chromium.launch(headless=True)
@@ -43,6 +46,7 @@ def select_area_with_opencv(image):
4346

4447
try:
4548
import cv2 as cv
49+
from PIL import ImageGrab
4650
except ImportError:
4751
raise ImportError("The dependencies for screenshot scraping are not installed. Please install them using `pip install scrapegraphai[screenshot_scraper]`.")
4852

0 commit comments

Comments
 (0)