automatically detect and bypass cloudflare challenge pages

TODO: cache and re-apply cfclearance cookies
This commit is contained in:
Mike Fährmann
2019-03-10 15:31:33 +01:00
parent 25aaf55514
commit 6dae6bee37
5 changed files with 55 additions and 57 deletions

View File

@@ -18,7 +18,7 @@ import requests
import threading
import http.cookiejar
from .message import Message
from .. import config, text, exception
from .. import config, text, exception, cloudflare
class Extractor():
@@ -86,6 +86,10 @@ class Extractor():
if encoding:
response.encoding = encoding
return response
if cloudflare.is_challenge(response):
self.log.info("Solving Cloudflare challenge")
url = cloudflare.solve_challenge(session, response, kwargs)
continue
msg = "{}: {} for url: {}".format(code, response.reason, url)
if code < 500 and code != 429: