Skip to content

Commit

Permalink
feat: pass new challenge (#56)
Browse files Browse the repository at this point in the history
* feat: pass new challenge

Signed-off-by: vvanglro <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: vvanglro <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
vvanglro and pre-commit-ci[bot] authored Jul 24, 2023
1 parent d34b562 commit e070838
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
1 change: 1 addition & 0 deletions docker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ChallengeResponse(BaseModel):
async def chromium(data: ChallengeRequest):
launch_data = {
"headless": False,
"devtools": True,
"proxy": {
"server": data.proxy.server,
"username": data.proxy.username,
Expand Down
5 changes: 3 additions & 2 deletions example/test_chromium_cron_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

async def test_cf_challenge(url: str):
# not use cf_clearance, cf challenge is fail
res = requests.get("https://nowsecure.nl")
res = requests.get(url)
assert "<title>Just a moment...</title>" in res.text
# get cf_clearance
with Display():
async with async_playwright() as p:
browser = await p.chromium.launch(
headless=False,
devtools=True,
)
context = await browser.new_context()
page = await context.new_page()
Expand All @@ -38,7 +39,7 @@ async def test_cf_challenge(url: str):
# use cf_clearance, must be same IP and UA
headers = {"user-agent": ua}
cookies = {"cf_clearance": cf_clearance_value}
res = requests.get("https://nowsecure.nl", headers=headers, cookies=cookies)
res = requests.get(url, headers=headers, cookies=cookies)
assert "<title>Just a moment...</title>" not in res.text


Expand Down
5 changes: 1 addition & 4 deletions example/test_firefox_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ async def test_cf_challenge(url: str):
assert "<title>Just a moment...</title>" in res.text
# get cf_clearance
async with async_playwright() as p:
browser = await p.firefox.launch(
headless=False,
)
browser = await p.firefox.launch(headless=False)
context = await browser.new_context()
page = await context.new_page()
await page.goto(url)
Expand All @@ -30,7 +28,6 @@ async def test_cf_challenge(url: str):
raise
else:
print("No cloudflare challenges encountered")

await browser.close()
# use cf_clearance, must be same IP and UA
headers = {"user-agent": ua}
Expand Down
36 changes: 31 additions & 5 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ dev = [
"fastapi==0.99.1",
"uvicorn==0.23.0",
"pyvirtualdisplay==3.0",
"requests==2.29.0",
"requests[socks]>=2.29.0",
]

2 comments on commit e070838

@cardermeister
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i love you

@vvanglro
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i love you

Hi, If it helps you, don't forget star.

Please sign in to comment.