feat(DynamicFetcher): Replace rebrowser with patchright
This commit is contained in:
@@ -58,7 +58,7 @@ jobs:
|
|||||||
- name: Install all browsers dependencies
|
- name: Install all browsers dependencies
|
||||||
run: |
|
run: |
|
||||||
python3 -m pip install --upgrade pip
|
python3 -m pip install --upgrade pip
|
||||||
python3 -m pip install playwright==1.52.0 rebrowser-playwright==1.52.0 camoufox
|
python3 -m pip install playwright>=1.55.0 patchright>=1.55.0 camoufox
|
||||||
|
|
||||||
- name: Retrieve Playwright browsers from cache if any
|
- name: Retrieve Playwright browsers from cache if any
|
||||||
id: playwright-cache
|
id: playwright-cache
|
||||||
|
|||||||
@@ -322,10 +322,9 @@ This project includes code adapted from:
|
|||||||
## Thanks and References
|
## Thanks and References
|
||||||
|
|
||||||
- [Daijro](https://github.com/daijro)'s brilliant work on [BrowserForge](https://github.com/daijro/browserforge) and [Camoufox](https://github.com/daijro/camoufox)
|
- [Daijro](https://github.com/daijro)'s brilliant work on [BrowserForge](https://github.com/daijro/browserforge) and [Camoufox](https://github.com/daijro/camoufox)
|
||||||
- [Vinyzu](https://github.com/Vinyzu)'s work on [Botright](https://github.com/Vinyzu/Botright)
|
- [Vinyzu](https://github.com/Vinyzu)'s brilliant work on [Botright](https://github.com/Vinyzu/Botright) and [PatchRight](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright)
|
||||||
- [brotector](https://github.com/kaliiiiiiiiii/brotector) for browser detection bypass techniques
|
- [brotector](https://github.com/kaliiiiiiiiii/brotector) for browser detection bypass techniques
|
||||||
- [fakebrowser](https://github.com/kkoooqq/fakebrowser) for fingerprinting research
|
- [fakebrowser](https://github.com/kkoooqq/fakebrowser) and [BotBrowser](https://github.com/botswin/BotBrowser) for fingerprinting research
|
||||||
- [rebrowser-patches](https://github.com/rebrowser/rebrowser-patches) for stealth improvements
|
|
||||||
|
|
||||||
---
|
---
|
||||||
<div align="center"><small>Designed & crafted with ❤️ by Karim Shoair.</small></div><br>
|
<div align="center"><small>Designed & crafted with ❤️ by Karim Shoair.</small></div><br>
|
||||||
@@ -35,7 +35,7 @@ It's the same as the vanilla Playwright option, but it provides a simple stealth
|
|||||||
|
|
||||||
Some of the things this fetcher's stealth mode does include:
|
Some of the things this fetcher's stealth mode does include:
|
||||||
|
|
||||||
* Patching the CDP runtime fingerprint.
|
* Patching the CDP runtime fingerprint through using PatchRight.
|
||||||
* Mimics some of the real browsers' properties by injecting several JS files and using custom options.
|
* Mimics some of the real browsers' properties by injecting several JS files and using custom options.
|
||||||
* Custom flags are used on launch to hide Playwright even more and make it faster.
|
* Custom flags are used on launch to hide Playwright even more and make it faster.
|
||||||
* Generates real browser headers of the same type and user OS, then appends them to the request's headers.
|
* Generates real browser headers of the same type and user OS, then appends them to the request's headers.
|
||||||
|
|||||||
+2
-2
@@ -66,8 +66,8 @@ dependencies = [
|
|||||||
fetchers = [
|
fetchers = [
|
||||||
"click>=8.2.1",
|
"click>=8.2.1",
|
||||||
"curl_cffi>=0.13.0",
|
"curl_cffi>=0.13.0",
|
||||||
"playwright>=1.52.0",
|
"playwright>=1.55.0",
|
||||||
"rebrowser-playwright>=1.52.0",
|
"patchright>=1.55.2",
|
||||||
"camoufox>=0.4.11",
|
"camoufox>=0.4.11",
|
||||||
"geoip2>=5.1.0",
|
"geoip2>=5.1.0",
|
||||||
"msgspec>=0.19.0",
|
"msgspec>=0.19.0",
|
||||||
|
|||||||
@@ -11,10 +11,8 @@ from playwright.async_api import (
|
|||||||
Playwright as AsyncPlaywright,
|
Playwright as AsyncPlaywright,
|
||||||
Locator as AsyncLocator,
|
Locator as AsyncLocator,
|
||||||
)
|
)
|
||||||
from rebrowser_playwright.sync_api import sync_playwright as sync_rebrowser_playwright
|
from patchright.sync_api import sync_playwright as sync_patchright
|
||||||
from rebrowser_playwright.async_api import (
|
from patchright.async_api import async_playwright as async_patchright
|
||||||
async_playwright as async_rebrowser_playwright,
|
|
||||||
)
|
|
||||||
|
|
||||||
from scrapling.core.utils import log
|
from scrapling.core.utils import log
|
||||||
from ._base import SyncSession, AsyncSession, DynamicSessionMixin
|
from ._base import SyncSession, AsyncSession, DynamicSessionMixin
|
||||||
@@ -154,10 +152,7 @@ class DynamicSession(DynamicSessionMixin, SyncSession):
|
|||||||
|
|
||||||
def __create__(self):
|
def __create__(self):
|
||||||
"""Create a browser for this instance and context."""
|
"""Create a browser for this instance and context."""
|
||||||
sync_context = sync_rebrowser_playwright
|
sync_context = sync_patchright if self.stealth else sync_playwright
|
||||||
if not self.stealth or self.real_chrome:
|
|
||||||
# Because rebrowser_playwright doesn't play well with real browsers
|
|
||||||
sync_context = sync_playwright
|
|
||||||
|
|
||||||
self.playwright: Playwright = sync_context().start()
|
self.playwright: Playwright = sync_context().start()
|
||||||
|
|
||||||
@@ -403,10 +398,7 @@ class AsyncDynamicSession(DynamicSessionMixin, AsyncSession):
|
|||||||
|
|
||||||
async def __create__(self):
|
async def __create__(self):
|
||||||
"""Create a browser for this instance and context."""
|
"""Create a browser for this instance and context."""
|
||||||
async_context = async_rebrowser_playwright
|
async_context = async_patchright if self.stealth else async_playwright
|
||||||
if not self.stealth or self.real_chrome:
|
|
||||||
# Because rebrowser_playwright doesn't play well with real browsers
|
|
||||||
async_context = async_playwright
|
|
||||||
|
|
||||||
self.playwright: AsyncPlaywright = await async_context().start()
|
self.playwright: AsyncPlaywright = await async_context().start()
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ envlist = pre-commit,py{310,311,312,313}
|
|||||||
usedevelop = True
|
usedevelop = True
|
||||||
changedir = tests
|
changedir = tests
|
||||||
deps =
|
deps =
|
||||||
playwright==1.52.0
|
playwright>=1.55.0
|
||||||
rebrowser-playwright==1.52.0
|
patchright>=1.55.0
|
||||||
camoufox
|
camoufox
|
||||||
-r{toxinidir}/tests/requirements.txt
|
-r{toxinidir}/tests/requirements.txt
|
||||||
extras = ai,shell
|
extras = ai,shell
|
||||||
|
|||||||
Reference in New Issue
Block a user