-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add firefox usage and example (#51)
* feat: add example Signed-off-by: vvanglro <[email protected]> * feat: add example Signed-off-by: vvanglro <[email protected]> * feat: update every_day_cron_challenge.yml Signed-off-by: vvanglro <[email protected]> * feat: update README.md Signed-off-by: vvanglro <[email protected]> * feat: update pre-commit Signed-off-by: vvanglro <[email protected]> --------- Signed-off-by: vvanglro <[email protected]>
- Loading branch information
Showing
6 changed files
with
97 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import requests | ||
from playwright.async_api import async_playwright | ||
|
||
from cf_clearance import async_cf_retry | ||
|
||
|
||
async def test_cf_challenge(url: str): | ||
# not use cf_clearance, cf challenge is fail | ||
res = requests.get("https://nowsecure.nl") | ||
assert "<title>Just a moment...</title>" in res.text | ||
# get cf_clearance | ||
async with async_playwright() as p: | ||
browser = await p.firefox.launch( | ||
headless=True, | ||
) | ||
context = await browser.new_context() | ||
page = await context.new_page() | ||
await page.goto(url) | ||
success, cf = await async_cf_retry(page) | ||
if cf: | ||
if success: | ||
cookies = await page.context.cookies() | ||
for cookie in cookies: | ||
if cookie.get("name") == "cf_clearance": | ||
cf_clearance_value = cookie.get("value") | ||
print(cf_clearance_value) | ||
ua = await page.evaluate("() => {return navigator.userAgent}") | ||
assert cf_clearance_value | ||
else: | ||
raise | ||
else: | ||
print("No cloudflare challenges encountered") | ||
|
||
await browser.close() | ||
# 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) | ||
assert "<title>Just a moment...</title>" not in res.text | ||
|
||
|
||
if __name__ == "__main__": | ||
import asyncio | ||
|
||
asyncio.run(test_cf_challenge("https://nowsecure.nl")) |