Skip to content

Commit

Permalink
improve web scrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
adbenitez committed Nov 9, 2024
1 parent 83d916d commit b9fb0d0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions dcstatus/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_html(
with sync_playwright() as playwright:
browser = playwright.chromium.launch()
if cookies is not None:
context = browser.new_context()
context = browser.new_context(user_agent=session.headers["User-Agent"])
context.add_cookies(cookies)
else:
context = None
Expand Down Expand Up @@ -57,14 +57,16 @@ def post(
) -> str:
with sync_playwright() as playwright:
browser = playwright.chromium.launch()
context = browser.new_context(base_url=base_url)
api_request_context = context.request
context = browser.new_context(
base_url=base_url, user_agent=session.headers["User-Agent"]
)
if cookies is not None:
context.add_cookies(cookies)
page = context.new_page()
try:
page.goto(base_url)
response = api_request_context.post(
time.sleep(3)
response = page.request.post(
url, headers=headers, form=form, data=json
).body()
except Exception as ex:
Expand Down

0 comments on commit b9fb0d0

Please sign in to comment.