-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to change User Agent
in PlaywrightCrawler
?
#751
Comments
- Enhance argument docstrings for `PlaywrightCrawler` (and propagate them further). - Mostly `browser_options` and `page_options`, and add links to the PW docs. - This previous state was clearly insufficient, e.g. #751.
As described in PR #753 , I specific user_agent to use but I still have an error:
|
Hi @LeMoussel, the When are we planning to make a new release @vdusek? |
Hi @LeMoussel, the You can now set the But if your goal is to replace the default |
It seems I'm missing something here. 🙂 import json
from crawlee import Request
from crawlee.playwright_crawler import PlaywrightCrawler, PlaywrightCrawlingContext
crawler = PlaywrightCrawler(
max_requests_per_crawl=1,
)
@crawler.router.default_handler
async def request_handler(context: PlaywrightCrawlingContext) -> None:
context.log.info(f"Processing {context.request.url} ...")
response = await context.response.text()
data = json.loads(response)
print(data['user-agent'])
await crawler.run(
[
Request.from_url(
url="https://httpbingo.org/user-agent",
headers={"User-Agent": "Test User Agent"},
)
]
) I get the following result:
As you can see, the User-Agent value hasn't changed. My goal is to replace the default Playwright user agent with my custom one, and I want to achieve this manually in my code, not automatically by crawlee-python. Note: I tested the same with |
You didn't miss anything, I completely missed that in And since When the fix for #755 is ready, that should allow you to set User-Agent for But we need to think about cases where some header can be overridden at the |
How can I change the user_agent in PlaywrightCrawler?
Here's what I tried:
However, I encountered the following error:
BrowserType.launch() got an unexpected keyword argument 'user_agent'.
The text was updated successfully, but these errors were encountered: