pass cloudflare
This commit is contained in:
parent
e1da4cb67a
commit
bef1b6918a
@ -20,6 +20,7 @@ class Site(Base):
|
|||||||
ua = Column(String)
|
ua = Column(String)
|
||||||
proxy = Column(Integer)
|
proxy = Column(Integer)
|
||||||
filter = Column(String)
|
filter = Column(String)
|
||||||
|
render = Column(Integer)
|
||||||
note = Column(String)
|
note = Column(String)
|
||||||
limit_interval = Column(Integer)
|
limit_interval = Column(Integer)
|
||||||
limit_count = Column(Integer)
|
limit_count = Column(Integer)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
from playwright.sync_api import sync_playwright
|
from playwright.sync_api import sync_playwright
|
||||||
|
from cf_clearance import sync_cf_retry, sync_stealth
|
||||||
from app.log import logger
|
from app.log import logger
|
||||||
|
|
||||||
|
|
||||||
@ -29,8 +29,11 @@ class PlaywrightHelper:
|
|||||||
if cookies:
|
if cookies:
|
||||||
page.set_extra_http_headers({"cookie": cookies})
|
page.set_extra_http_headers({"cookie": cookies})
|
||||||
try:
|
try:
|
||||||
|
sync_stealth(page, pure=True)
|
||||||
page.goto(url)
|
page.goto(url)
|
||||||
|
res = sync_cf_retry(page)
|
||||||
|
if not res:
|
||||||
|
logger.warn("cloudflare challenge fail!")
|
||||||
page.wait_for_load_state("networkidle", timeout=timeout * 1000)
|
page.wait_for_load_state("networkidle", timeout=timeout * 1000)
|
||||||
source = page.content()
|
source = page.content()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -45,8 +48,8 @@ class PlaywrightHelper:
|
|||||||
# 示例用法
|
# 示例用法
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
utils = PlaywrightHelper()
|
utils = PlaywrightHelper()
|
||||||
test_url = "https://www.baidu.com"
|
test_url = "https://piggo.me"
|
||||||
test_cookies = "cookie1=value1; cookie2=value2"
|
test_cookies = ""
|
||||||
test_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
|
test_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36"
|
||||||
source_code = utils.get_page_source(test_url, cookies=test_cookies, ua=test_user_agent)
|
source_code = utils.get_page_source(test_url, cookies=test_cookies, ua=test_user_agent)
|
||||||
print(source_code)
|
print(source_code)
|
||||||
|
@ -14,6 +14,7 @@ class Site(BaseModel):
|
|||||||
ua: Optional[str] = None
|
ua: Optional[str] = None
|
||||||
proxy: Optional[int] = 0
|
proxy: Optional[int] = 0
|
||||||
filter: Optional[str] = None
|
filter: Optional[str] = None
|
||||||
|
render: Optional[int] = 0
|
||||||
note: Optional[str] = None
|
note: Optional[str] = None
|
||||||
limit_interval: Optional[int] = 0
|
limit_interval: Optional[int] = 0
|
||||||
limit_count: Optional[int] = 0
|
limit_count: Optional[int] = 0
|
||||||
|
@ -37,3 +37,4 @@ beautifulsoup4~=4.12.2
|
|||||||
pillow~=9.5.0
|
pillow~=9.5.0
|
||||||
pyTelegramBotAPI~=4.12.0
|
pyTelegramBotAPI~=4.12.0
|
||||||
playwright~=1.34.0
|
playwright~=1.34.0
|
||||||
|
cf_clearance~=0.29.2
|
Loading…
x
Reference in New Issue
Block a user