Ultimate update for PyNyaaTa before turning to NodeJS
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
72857d4d6d
commit
35c59031b4
@ -1,64 +1,5 @@
|
|||||||
import re
|
from cloudscraper import CloudScraper
|
||||||
from collections import OrderedDict
|
|
||||||
from urllib.parse import urlparse
|
|
||||||
|
|
||||||
from cloudscraper import CloudScraper, CloudflareIUAMError, JavaScriptInterpreter
|
|
||||||
|
|
||||||
|
|
||||||
class CloudScraperWrapper(CloudScraper):
|
class CloudScraperWrapper(CloudScraper):
|
||||||
|
pass
|
||||||
def IUAM_Challenge_Response(self, body, url, interpreter):
|
|
||||||
try:
|
|
||||||
formPayload = re.search(
|
|
||||||
r'<form (?P<form>.*?="challenge-form" '
|
|
||||||
r'action="(?P<challengeUUID>.*?'
|
|
||||||
r'__cf_chl_jschl_tk__=\S+)"(.*?)</form>)',
|
|
||||||
body,
|
|
||||||
re.M | re.DOTALL
|
|
||||||
).groupdict()
|
|
||||||
|
|
||||||
if not all(key in formPayload for key in ['form', 'challengeUUID']):
|
|
||||||
self.simpleException(
|
|
||||||
CloudflareIUAMError,
|
|
||||||
"Cloudflare IUAM detected, unfortunately we can't extract the parameters correctly."
|
|
||||||
)
|
|
||||||
|
|
||||||
payload = OrderedDict()
|
|
||||||
for challengeParam in re.findall(r'<input\s(.*?)>', formPayload['form']):
|
|
||||||
inputPayload = dict(re.findall(r'(\S+)="(\S+)"', challengeParam))
|
|
||||||
|
|
||||||
if inputPayload.get('name') in ['r', 'jschl_vc', 'pass']:
|
|
||||||
if inputPayload.get('name') != "jschl_vc":
|
|
||||||
|
|
||||||
payload.update({inputPayload['name']: inputPayload['value']})
|
|
||||||
elif inputPayload.get('name') == "jschl_vc" and "jschl_vc" not in payload:
|
|
||||||
payload.update({inputPayload['name']: inputPayload['value']})
|
|
||||||
|
|
||||||
except AttributeError:
|
|
||||||
self.simpleException(
|
|
||||||
CloudflareIUAMError,
|
|
||||||
"Cloudflare IUAM detected, unfortunately we can't extract the parameters correctly."
|
|
||||||
)
|
|
||||||
|
|
||||||
hostParsed = urlparse(url)
|
|
||||||
|
|
||||||
try:
|
|
||||||
payload['jschl_answer'] = JavaScriptInterpreter.dynamicImport(
|
|
||||||
interpreter
|
|
||||||
).solveChallenge(body, hostParsed.netloc)
|
|
||||||
except Exception as e:
|
|
||||||
self.simpleException(
|
|
||||||
CloudflareIUAMError,
|
|
||||||
'Unable to parse Cloudflare anti-bots page: {}'.format(
|
|
||||||
getattr(e, 'message', e)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
'url': '{}://{}{}'.format(
|
|
||||||
hostParsed.scheme,
|
|
||||||
hostParsed.netloc,
|
|
||||||
self.unescape(formPayload['challengeUUID'])
|
|
||||||
),
|
|
||||||
'data': payload
|
|
||||||
}
|
|
||||||
|
@ -7,5 +7,5 @@ PyMySQL==0.9.3
|
|||||||
requests==2.23.0
|
requests==2.23.0
|
||||||
beautifulsoup4==4.9.0
|
beautifulsoup4==4.9.0
|
||||||
python-dotenv==0.13.0
|
python-dotenv==0.13.0
|
||||||
cloudscraper==1.2.36
|
cloudscraper==1.2.38
|
||||||
dateparser==0.7.4
|
dateparser==0.7.4
|
||||||
|
Reference in New Issue
Block a user