Skip to content

Commit

Permalink
save cookies between requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhaseless committed Dec 12, 2024
1 parent e2114d7 commit a31aa1e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, log_level=LOG_LEVEL)

cookies = []


@app.get("/")
def read_root():
Expand Down Expand Up @@ -56,6 +58,10 @@ def read_item(request: LinkRequest) -> LinkResponse:
with SB(uc=True, locale_code="en", test=False, xvfb=True, ad_block=True) as sb:
try:
sb: BaseCase
global cookies # noqa: PLW0603
if cookies:
sb.uc_open_with_reconnect(request.url)
sb.add_cookies(cookies)
sb.uc_open_with_reconnect(request.url)
source = sb.get_page_source()
source_bs = BeautifulSoup(source, "html.parser")
Expand Down Expand Up @@ -86,6 +92,7 @@ def read_item(request: LinkRequest) -> LinkResponse:
),
startTimestamp=start_time,
)
cookies = sb.get_cookies()
except Exception as e:
logger.error(f"Error: {e}")
if sb.driver:
Expand Down

0 comments on commit a31aa1e

Please sign in to comment.