Fix build: Bundle schwab_scraper source and use local dependencies
All checks were successful
Build and Push Docker Image / build (push) Successful in 34s
All checks were successful
Build and Push Docker Image / build (push) Successful in 34s
This commit is contained in:
30
schwab_scraper/browser/client.py
Normal file
30
schwab_scraper/browser/client.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from typing import Any
|
||||
from playwright.async_api import async_playwright
|
||||
|
||||
|
||||
async def connect(playwright_url: str):
|
||||
p = await async_playwright().start()
|
||||
browser = await p.chromium.connect(playwright_url)
|
||||
return p, browser
|
||||
|
||||
|
||||
async def new_context(browser, cookies: list[dict] | None = None, user_agent: str | None = None):
|
||||
context = await browser.new_context(
|
||||
user_agent=user_agent or 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
|
||||
)
|
||||
if cookies:
|
||||
valid_same_site_values = ['Strict', 'Lax', 'None']
|
||||
for cookie in cookies:
|
||||
if cookie.get('sameSite') not in valid_same_site_values:
|
||||
if cookie.get('sameSite') == 'no_restriction':
|
||||
cookie['sameSite'] = 'None'
|
||||
else:
|
||||
cookie['sameSite'] = 'Lax'
|
||||
await context.add_cookies(cookies) # type: ignore
|
||||
return context
|
||||
|
||||
|
||||
async def new_page(context):
|
||||
return await context.new_page()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user