PlaywrightCapture 1.31.6__py3-none-any.whl → 1.32.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- playwrightcapture/__init__.py +4 -0
- playwrightcapture/capture.py +64 -18
- {playwrightcapture-1.31.6.dist-info → playwrightcapture-1.32.0.dist-info}/METADATA +3 -3
- playwrightcapture-1.32.0.dist-info/RECORD +10 -0
- playwrightcapture-1.31.6.dist-info/RECORD +0 -10
- {playwrightcapture-1.31.6.dist-info → playwrightcapture-1.32.0.dist-info}/LICENSE +0 -0
- {playwrightcapture-1.31.6.dist-info → playwrightcapture-1.32.0.dist-info}/WHEEL +0 -0
playwrightcapture/__init__.py
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
from .capture import Capture # noqa
|
2
|
+
from .capture import CaptureResponse # noqa
|
3
|
+
from .capture import SetCookieParam, Cookie # noqa
|
2
4
|
from .helpers import get_devices # noqa
|
3
5
|
from .exceptions import (PlaywrightCaptureException, UnknownPlaywrightDeviceType, # noqa
|
4
6
|
UnknownPlaywrightBrowser, UnknownPlaywrightDevice,
|
@@ -6,6 +8,8 @@ from .exceptions import (PlaywrightCaptureException, UnknownPlaywrightDeviceType
|
|
6
8
|
|
7
9
|
__all__ = [
|
8
10
|
'Capture',
|
11
|
+
'CaptureResponse',
|
12
|
+
'SetCookieParam', 'Cookie',
|
9
13
|
'get_devices',
|
10
14
|
'PlaywrightCaptureException',
|
11
15
|
'UnknownPlaywrightDeviceType',
|
playwrightcapture/capture.py
CHANGED
@@ -46,18 +46,6 @@ if sys.version_info < (3, 11):
|
|
46
46
|
else:
|
47
47
|
from asyncio import timeout
|
48
48
|
|
49
|
-
if sys.version_info < (3, 12):
|
50
|
-
from typing_extensions import TypedDict
|
51
|
-
else:
|
52
|
-
from typing import TypedDict
|
53
|
-
|
54
|
-
if TYPE_CHECKING:
|
55
|
-
from playwright._impl._api_structures import (SetCookieParam, Geolocation,
|
56
|
-
HttpCredentials, Headers,
|
57
|
-
ViewportSize, Cookie,
|
58
|
-
ProxySettings, StorageState)
|
59
|
-
BROWSER = Literal['chromium', 'firefox', 'webkit']
|
60
|
-
|
61
49
|
try:
|
62
50
|
if sys.version_info < (3, 10):
|
63
51
|
from pydub import AudioSegment # type: ignore[attr-defined]
|
@@ -68,6 +56,54 @@ try:
|
|
68
56
|
except ImportError:
|
69
57
|
CAN_SOLVE_CAPTCHA = False
|
70
58
|
|
59
|
+
# ####
|
60
|
+
# This bit is required as long as we need to support python < 3.12, stop removing it, you idiot
|
61
|
+
# That's the runtime failure: https://github.com/ail-project/lacus/actions/runs/16447900822/job/46484807036
|
62
|
+
# And the MyPy failure: https://github.com/ail-project/LacusCore/actions/runs/16447753492/job/46484287947
|
63
|
+
if sys.version_info < (3, 12):
|
64
|
+
from typing_extensions import TypedDict
|
65
|
+
else:
|
66
|
+
from typing import TypedDict
|
67
|
+
|
68
|
+
# These two classes are copies of te ones in Playwright, we need them until we can discard python 3.11
|
69
|
+
# They come from this file:
|
70
|
+
# https://github.com/microsoft/playwright-python/blob/main/playwright/_impl/_api_structures.py
|
71
|
+
|
72
|
+
|
73
|
+
class SetCookieParam(TypedDict, total=False):
|
74
|
+
name: str
|
75
|
+
value: str
|
76
|
+
url: str
|
77
|
+
domain: str
|
78
|
+
path: str
|
79
|
+
expires: float
|
80
|
+
httpOnly: bool
|
81
|
+
secure: bool
|
82
|
+
sameSite: Literal["Lax", "None", "Strict"]
|
83
|
+
partitionKey: str
|
84
|
+
|
85
|
+
|
86
|
+
class Cookie(TypedDict, total=False):
|
87
|
+
name: str
|
88
|
+
value: str
|
89
|
+
domain: str
|
90
|
+
path: str
|
91
|
+
expires: float
|
92
|
+
httpOnly: bool
|
93
|
+
secure: bool
|
94
|
+
sameSite: Literal["Lax", "None", "Strict"]
|
95
|
+
partitionKey: str
|
96
|
+
|
97
|
+
# ####################################
|
98
|
+
|
99
|
+
|
100
|
+
if TYPE_CHECKING:
|
101
|
+
from playwright._impl._api_structures import (Geolocation,
|
102
|
+
HttpCredentials, Headers,
|
103
|
+
ViewportSize,
|
104
|
+
ProxySettings, StorageState)
|
105
|
+
BROWSER = Literal['chromium', 'firefox', 'webkit']
|
106
|
+
|
71
107
|
|
72
108
|
class CaptureResponse(TypedDict, total=False):
|
73
109
|
|
@@ -198,8 +234,6 @@ class Capture():
|
|
198
234
|
|
199
235
|
async def __aenter__(self) -> Capture:
|
200
236
|
'''Launch the browser'''
|
201
|
-
self._temp_harfile = NamedTemporaryFile(delete=False)
|
202
|
-
|
203
237
|
self.playwright = await async_playwright().start()
|
204
238
|
|
205
239
|
if self.device_name:
|
@@ -219,11 +253,12 @@ class Capture():
|
|
219
253
|
# Set of URLs that were captured in that context
|
220
254
|
self._already_captured: set[str] = set()
|
221
255
|
|
256
|
+
# Create the temporary file to store the HAR content.
|
257
|
+
self._temp_harfile = NamedTemporaryFile(delete=False, prefix="playwright_capture_har", suffix=".json")
|
258
|
+
|
222
259
|
return self
|
223
260
|
|
224
261
|
async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> bool:
|
225
|
-
if hasattr(self, '_temp_harfile'):
|
226
|
-
os.unlink(self._temp_harfile.name)
|
227
262
|
|
228
263
|
try:
|
229
264
|
await self.browser.close(reason="Closing browser at the end of the capture.")
|
@@ -235,6 +270,13 @@ class Capture():
|
|
235
270
|
except Exception as e:
|
236
271
|
# this should't happen, but just in case it does...
|
237
272
|
self.logger.info(f'Unable to stop playwright: {e}')
|
273
|
+
|
274
|
+
if hasattr(self, '_temp_harfile'):
|
275
|
+
try:
|
276
|
+
os.unlink(self._temp_harfile.name)
|
277
|
+
except Exception as e:
|
278
|
+
self.logger.warning(f'Unable to remove temp HAR file {self._temp_harfile.name}: {e}')
|
279
|
+
|
238
280
|
return True
|
239
281
|
|
240
282
|
@property
|
@@ -515,7 +557,9 @@ class Capture():
|
|
515
557
|
|
516
558
|
if self.cookies:
|
517
559
|
try:
|
518
|
-
|
560
|
+
# NOTE: Ignore type until we can use python 3.12 + only
|
561
|
+
# playwrightcapture.capture.SetCookieParam == playwright._impl._api_structures.SetCookieParam
|
562
|
+
await self.context.add_cookies(self.cookies) # type: ignore[arg-type]
|
519
563
|
except Exception:
|
520
564
|
self.logger.exception(f'Unable to set cookies: {self.cookies}')
|
521
565
|
|
@@ -1237,7 +1281,9 @@ class Capture():
|
|
1237
1281
|
|
1238
1282
|
try:
|
1239
1283
|
async with timeout(15):
|
1240
|
-
|
1284
|
+
# NOTE: Ignore type until we can use python 3.12 + only
|
1285
|
+
# playwrightcapture.capture.SetCookieParam == playwright._impl._api_structures.SetCookieParam
|
1286
|
+
to_return['cookies'] = await self.context.cookies() # type: ignore[typeddict-item]
|
1241
1287
|
except (TimeoutError, asyncio.TimeoutError):
|
1242
1288
|
self.logger.warning("Unable to get cookies (timeout).")
|
1243
1289
|
errors.append("Unable to get the cookies (timeout).")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: PlaywrightCapture
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.32.0
|
4
4
|
Summary: A simple library to capture websites using playwright
|
5
5
|
License: BSD-3-Clause
|
6
6
|
Author: Raphaël Vinot
|
@@ -20,9 +20,9 @@ Classifier: Topic :: Security
|
|
20
20
|
Provides-Extra: recaptcha
|
21
21
|
Requires-Dist: SpeechRecognition (>=3.14.3) ; extra == "recaptcha"
|
22
22
|
Requires-Dist: aiohttp-socks (>=0.10.1)
|
23
|
-
Requires-Dist: aiohttp[speedups] (>=3.12.
|
23
|
+
Requires-Dist: aiohttp[speedups] (>=3.12.15)
|
24
24
|
Requires-Dist: async-timeout (>=5.0.1) ; python_version < "3.11"
|
25
|
-
Requires-Dist: beautifulsoup4[charset-normalizer,lxml] (>=4.13.
|
25
|
+
Requires-Dist: beautifulsoup4[charset-normalizer,lxml] (>=4.13.5)
|
26
26
|
Requires-Dist: dateparser (>=1.2.2)
|
27
27
|
Requires-Dist: dnspython (>=2.7.0,<3.0.0)
|
28
28
|
Requires-Dist: playwright (>=1.54.0)
|
@@ -0,0 +1,10 @@
|
|
1
|
+
playwrightcapture/__init__.py,sha256=NAL0-ymloDBm_ghp1PsefIwRMQmEFKPhn83WVUD7t_0,663
|
2
|
+
playwrightcapture/capture.py,sha256=yPGhrhFrwKS7mlTeMw_acYIjlDHZnAR0psOdXKoi4Lw,88922
|
3
|
+
playwrightcapture/exceptions.py,sha256=LhGJQCGHzEu7Sx2Dfl28OFeDg1OmrwufFjAWXlxQnEA,366
|
4
|
+
playwrightcapture/helpers.py,sha256=Xqs09zHhzAWnpBtQ0A9YAxg80P3Lj7aBj5M2WuEr0so,1843
|
5
|
+
playwrightcapture/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
+
playwrightcapture/socks5dnslookup.py,sha256=ZpOf8tgsRQZi-WDcn9JbbG1bKz9DSfK_jz1l53UI1Ho,4058
|
7
|
+
playwrightcapture-1.32.0.dist-info/LICENSE,sha256=uwFc39fTLacBUG-XTuxX6IQKTKhg4z14gWOLt3ex4Ho,1775
|
8
|
+
playwrightcapture-1.32.0.dist-info/METADATA,sha256=2xaXTHpeA5DICsbA2k7ygsPrjOGZzLlSiYc6tl6h33E,3285
|
9
|
+
playwrightcapture-1.32.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
10
|
+
playwrightcapture-1.32.0.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
playwrightcapture/__init__.py,sha256=F90Y8wYS13tDjgsfjuFrCfmzQfdnH44G-ovuilJfLEE,511
|
2
|
-
playwrightcapture/capture.py,sha256=0coNzognowvVhFK87kNTl6d3cacsEEA0Thx8Nz0ZYxY,87183
|
3
|
-
playwrightcapture/exceptions.py,sha256=LhGJQCGHzEu7Sx2Dfl28OFeDg1OmrwufFjAWXlxQnEA,366
|
4
|
-
playwrightcapture/helpers.py,sha256=Xqs09zHhzAWnpBtQ0A9YAxg80P3Lj7aBj5M2WuEr0so,1843
|
5
|
-
playwrightcapture/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
|
-
playwrightcapture/socks5dnslookup.py,sha256=ZpOf8tgsRQZi-WDcn9JbbG1bKz9DSfK_jz1l53UI1Ho,4058
|
7
|
-
playwrightcapture-1.31.6.dist-info/LICENSE,sha256=uwFc39fTLacBUG-XTuxX6IQKTKhg4z14gWOLt3ex4Ho,1775
|
8
|
-
playwrightcapture-1.31.6.dist-info/METADATA,sha256=MuiFWvqR48aKPlOu6mHhohOdygHa869cS-8qasGlUV0,3285
|
9
|
-
playwrightcapture-1.31.6.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
10
|
-
playwrightcapture-1.31.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|