PlaywrightFetcher - Add the option to set locale of the browser
This commit is contained in:
@@ -317,6 +317,7 @@ Add that to a lot of controlling/hiding options as you will see in the arguments
|
|||||||
| disable_webgl | Disables WebGL and WebGL 2.0 support entirely. | ✔️ |
|
| disable_webgl | Disables WebGL and WebGL 2.0 support entirely. | ✔️ |
|
||||||
| stealth | Enables stealth mode, always check the documentation to see what stealth mode does currently. | ✔️ |
|
| stealth | Enables stealth mode, always check the documentation to see what stealth mode does currently. | ✔️ |
|
||||||
| real_chrome | If you have chrome browser installed on your device, enable this and the Fetcher will launch an instance of your browser and use it. | ✔️ |
|
| real_chrome | If you have chrome browser installed on your device, enable this and the Fetcher will launch an instance of your browser and use it. | ✔️ |
|
||||||
|
| locale | Set the locale for the browser if wanted. The default value is `en-US`. | ✔️ |
|
||||||
| cdp_url | Instead of launching a new browser instance, connect to this CDP URL to control real browsers/NSTBrowser through CDP. | ✔️ |
|
| cdp_url | Instead of launching a new browser instance, connect to this CDP URL to control real browsers/NSTBrowser through CDP. | ✔️ |
|
||||||
| nstbrowser_mode | Enables NSTBrowser mode, **it have to be used with `cdp_url` argument or it will get completely ignored.** | ✔️ |
|
| nstbrowser_mode | Enables NSTBrowser mode, **it have to be used with `cdp_url` argument or it will get completely ignored.** | ✔️ |
|
||||||
| nstbrowser_config | The config you want to send with requests to the NSTBrowser. _If left empty, Scrapling defaults to an optimized NSTBrowser's docker browserless config._ | ✔️ |
|
| nstbrowser_config | The config you want to send with requests to the NSTBrowser. _If left empty, Scrapling defaults to an optimized NSTBrowser's docker browserless config._ | ✔️ |
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class PlaywrightEngine:
|
|||||||
timeout: Optional[float] = 30000,
|
timeout: Optional[float] = 30000,
|
||||||
page_action: Callable = do_nothing,
|
page_action: Callable = do_nothing,
|
||||||
wait_selector: Optional[str] = None,
|
wait_selector: Optional[str] = None,
|
||||||
|
locale: Optional[str] = 'en-US',
|
||||||
wait_selector_state: Optional[str] = 'attached',
|
wait_selector_state: Optional[str] = 'attached',
|
||||||
stealth: Optional[bool] = False,
|
stealth: Optional[bool] = False,
|
||||||
real_chrome: Optional[bool] = False,
|
real_chrome: Optional[bool] = False,
|
||||||
@@ -50,6 +51,7 @@ class PlaywrightEngine:
|
|||||||
:param timeout: The timeout in milliseconds that is used in all operations and waits through the page. The default is 30000
|
:param timeout: The timeout in milliseconds that is used in all operations and waits through the page. The default is 30000
|
||||||
:param page_action: Added for automation. A function that takes the `page` object, does the automation you need, then returns `page` again.
|
:param page_action: Added for automation. A function that takes the `page` object, does the automation you need, then returns `page` again.
|
||||||
:param wait_selector: Wait for a specific css selector to be in a specific state.
|
:param wait_selector: Wait for a specific css selector to be in a specific state.
|
||||||
|
:param locale: Set the locale for the browser if wanted. The default value is `en-US`.
|
||||||
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. Default state is `attached`.
|
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. Default state is `attached`.
|
||||||
:param stealth: Enables stealth mode, check the documentation to see what stealth mode does currently.
|
:param stealth: Enables stealth mode, check the documentation to see what stealth mode does currently.
|
||||||
:param real_chrome: If you have chrome browser installed on your device, enable this and the Fetcher will launch an instance of your browser and use it.
|
:param real_chrome: If you have chrome browser installed on your device, enable this and the Fetcher will launch an instance of your browser and use it.
|
||||||
@@ -64,6 +66,7 @@ class PlaywrightEngine:
|
|||||||
:param adaptor_arguments: The arguments that will be passed in the end while creating the final Adaptor's class.
|
:param adaptor_arguments: The arguments that will be passed in the end while creating the final Adaptor's class.
|
||||||
"""
|
"""
|
||||||
self.headless = headless
|
self.headless = headless
|
||||||
|
self.locale = check_type_validity(locale, [str], 'en-US', param_name='locale')
|
||||||
self.disable_resources = disable_resources
|
self.disable_resources = disable_resources
|
||||||
self.network_idle = bool(network_idle)
|
self.network_idle = bool(network_idle)
|
||||||
self.stealth = bool(stealth)
|
self.stealth = bool(stealth)
|
||||||
@@ -159,7 +162,7 @@ class PlaywrightEngine:
|
|||||||
# Creating the context
|
# Creating the context
|
||||||
if self.stealth:
|
if self.stealth:
|
||||||
context = browser.new_context(
|
context = browser.new_context(
|
||||||
locale='en-US',
|
locale=self.locale,
|
||||||
is_mobile=False,
|
is_mobile=False,
|
||||||
has_touch=False,
|
has_touch=False,
|
||||||
proxy=self.proxy,
|
proxy=self.proxy,
|
||||||
@@ -176,6 +179,7 @@ class PlaywrightEngine:
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
context = browser.new_context(
|
context = browser.new_context(
|
||||||
|
locale=self.locale,
|
||||||
proxy=self.proxy,
|
proxy=self.proxy,
|
||||||
color_scheme='dark',
|
color_scheme='dark',
|
||||||
user_agent=useragent,
|
user_agent=useragent,
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ class PlayWrightFetcher(BaseFetcher):
|
|||||||
useragent: Optional[str] = None, network_idle: Optional[bool] = False, timeout: Optional[float] = 30000,
|
useragent: Optional[str] = None, network_idle: Optional[bool] = False, timeout: Optional[float] = 30000,
|
||||||
page_action: Optional[Callable] = do_nothing, wait_selector: Optional[str] = None, wait_selector_state: Optional[str] = 'attached',
|
page_action: Optional[Callable] = do_nothing, wait_selector: Optional[str] = None, wait_selector_state: Optional[str] = 'attached',
|
||||||
hide_canvas: Optional[bool] = False, disable_webgl: Optional[bool] = False, extra_headers: Optional[Dict[str, str]] = None, google_search: Optional[bool] = True,
|
hide_canvas: Optional[bool] = False, disable_webgl: Optional[bool] = False, extra_headers: Optional[Dict[str, str]] = None, google_search: Optional[bool] = True,
|
||||||
proxy: Optional[Union[str, Dict[str, str]]] = None,
|
proxy: Optional[Union[str, Dict[str, str]]] = None, locale: Optional[str] = 'en-US',
|
||||||
stealth: Optional[bool] = False, real_chrome: Optional[bool] = False,
|
stealth: Optional[bool] = False, real_chrome: Optional[bool] = False,
|
||||||
cdp_url: Optional[str] = None,
|
cdp_url: Optional[str] = None,
|
||||||
nstbrowser_mode: Optional[bool] = False, nstbrowser_config: Optional[Dict] = None,
|
nstbrowser_mode: Optional[bool] = False, nstbrowser_config: Optional[Dict] = None,
|
||||||
@@ -163,6 +163,7 @@ class PlayWrightFetcher(BaseFetcher):
|
|||||||
:param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
|
:param useragent: Pass a useragent string to be used. Otherwise the fetcher will generate a real Useragent of the same browser and use it.
|
||||||
:param network_idle: Wait for the page until there are no network connections for at least 500 ms.
|
:param network_idle: Wait for the page until there are no network connections for at least 500 ms.
|
||||||
:param timeout: The timeout in milliseconds that is used in all operations and waits through the page. The default is 30000
|
:param timeout: The timeout in milliseconds that is used in all operations and waits through the page. The default is 30000
|
||||||
|
:param locale: Set the locale for the browser if wanted. The default value is `en-US`.
|
||||||
:param page_action: Added for automation. A function that takes the `page` object, does the automation you need, then returns `page` again.
|
:param page_action: Added for automation. A function that takes the `page` object, does the automation you need, then returns `page` again.
|
||||||
:param wait_selector: Wait for a specific css selector to be in a specific state.
|
:param wait_selector: Wait for a specific css selector to be in a specific state.
|
||||||
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. Default state is `attached`.
|
:param wait_selector_state: The state to wait for the selector given with `wait_selector`. Default state is `attached`.
|
||||||
@@ -180,6 +181,7 @@ class PlayWrightFetcher(BaseFetcher):
|
|||||||
"""
|
"""
|
||||||
engine = PlaywrightEngine(
|
engine = PlaywrightEngine(
|
||||||
proxy=proxy,
|
proxy=proxy,
|
||||||
|
locale=locale,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
stealth=stealth,
|
stealth=stealth,
|
||||||
cdp_url=cdp_url,
|
cdp_url=cdp_url,
|
||||||
|
|||||||
Reference in New Issue
Block a user