Skip to content

Captcha Appeared #34

@Faizan-26

Description

@Faizan-26

Got a response after some debugging and modification in code according to new updates with time in website and got a response but that response is actually a page asking to fill for captcha:

Changes i made may helpful for someone continuing this :
def getQuesAns(self, q_url):
try:
res = requests.get(url=q_url, headers=self.web_heads, verify=False)
if 'questions-and-answers' in q_url:
try:
soup = BeautifulSoup(res.text, 'html.parser')
with open('soup.html', 'w', encoding='utf-8') as fp:
fp.write(str(soup))
dd = soup.find('script', attrs={'id': 'NEXT_DATA'})
js = json.loads(dd.text)
with open('props.html', 'w', encoding='utf-8') as fp:
fp.write(str(js['props']))

                with open('page_props.html', 'w', encoding='utf-8') as fp:
                    fp.write(str(js['props']['pageProps']))                    
                # q_id = js['props']['pageProps']['questionData']['uuid']
                q_id = js['props']['pageProps']['questionResult']['question']['uuid']
                print("[*]  Q_ID is ", q_id)

            except:
                print('[*] Error in getting question id ON LINE 156')
                q_id = res.text.split('questionUuid":"')[1].split('"}')[0]

            print("HEEERE")
            datax = {
                'id': 'getQuestionByUuid',
                'operationName': 'getQuestionByUuid',
                'variables': {
                    'questionUuid': q_id
                }
            }
            print("datax is ", datax)

            with open('settings.json', 'r') as fp:
                jsd = json.loads(fp.read())
            
            access_token = jsd['access_token']
            heads = {
                'user-agent': 'CheggApp/3.39.0 (com.chegg.mobile.consumer; build:3.39.0.0; iOS 14.5.0) Alamofire/5.2.2',
                'authorization': 'Basic MFQxOE5HYmFsUURGYzBnWkh6b3ZwZVJkN0E1Y3BMQ3g6dnRnamFZa3Ric2p4OUFPUg==',
                'Content-Type': 'application/json',
                'Connection': 'keep-alive',
                'access_token': access_token
            }
            print("Posting a request")
            res = requests.post(url=self.getAns, json=datax, headers=heads, verify=False)
            print("Recieved a response in response.txt and responseSTRING.txt and responseJSON.txt")
            #write to file
            with open('response.txt', 'w', encoding='utf-8') as ffff:
                ffff.write(res.text)
            with open('responseSTRING.txt', 'w', encoding='utf-8') as ffww:
                ffww.write(str(res))
            with open('responseJSON.txt', 'w', encoding='utf-8') as ffff:
                ffff.write(res.json())
            js = res.json()

            totalAns = len(js['data']['getQuestionByUuid']['answers'])
            ans = ''
            filename = './answers/answer_' + ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)) + '.html'
            if len(js['data']['getQuestionByUuid']['answers']) > 0:
                if js['data']['getQuestionByUuid']['answers'][0]['accessDetails']['hasAccess']:
                        for indd, i in enumerate(js['data']['getQuestionByUuid']['answers']):
                            ans += '<br><h1>Answer - ' + str(indd + 1) + '</h1><br>' + i['body']
                        with open(filename, 'w', encoding='utf-8') as fp:
                            fp.write(str(ans))
                    
                        return True, filename, 'Success'
                else:
                    return False, '', 'You dont have access'
            else:
                return False, '', 'Not Answered Yet!!'
        else:
            problemId = res.text.split('"problemId":"')[1].split('",')[0]
            isbn13 = res.text.split('"isbn13":"')[1].split('",')[0]
            datax = {
                'problemId': problemId,
                'isbn13': isbn13,
                'userAgent': 'Mobile'
            }

            heads = {
                'user-agent': 'CheggApp/3.39.0 (com.chegg.mobile.consumer; build:3.39.0.0; iOS 14.5.0) Alamofire/5.2.2',
                'authorization': 'Basic MFQxOE5HYmFsUURGYzBnWkh6b3ZwZVJkN0E1Y3BMQ3g6dnRnamFZa3Ric2p4OUFPUg==',
                'Content-Type': 'application/json',
                'Connection': 'keep-alive'
            }

            resp1 = requests.post(url=self.tbs, json=datax, headers=heads, verify=False)
            js1 = resp1.json()
            if js1['httpCode'] == 200:
                if len(js1['result']['solutions']) > 0:
                    filename = './answers/answer_' + ''.join(random.choice(string.ascii_lowercase + string.digits) for _ in range(10)) + '.html'
                    datac = ''
                    for indd, x in enumerate(js1['result']['solutions'][0]['steps']):
                        datac += '<br><H1>Step - ' + str(indd + 1) + '<br>' + requests.get(x['link'], verify=False).text
                    
                    with open(filename, 'w', encoding='utf-8') as fp:
                        fp.write(str(datac))
                    return True, filename, 'Success'
                
                else:
                    return False, '', 'Not answered'
    except Exception as e:
        return False, '', str(e)
        
        
        
        
        
        
        
        
        
        
        
       Response i got 
       
       
       `
<title>Access to this page has been denied</title> <script> /* PerimeterX assignments */ window._pxVid = ''; window._pxUuid = 'dd97996f-742d-11ef-b4ae-3f85b5657c5a'; window._pxAppId = 'PXaOtQIWNf'; window._pxHostUrl = '/aOtQIWNf/xhr'; window._pxCustomLogo = 'https://chegg-mobile-promotions.cheggcdn.com/px/Chegg-logo-79X22.png'; window._pxJsClientSrc = '/aOtQIWNf/init.js'; window._pxMobile = false; window._pxFirstPartyEnabled = true;
    var pxCaptchaSrc = '/aOtQIWNf/captcha/captcha.js?a=c&u=dd97996f-742d-11ef-b4ae-3f85b5657c5a&v=&m=0&b=aHR0cHM6Ly9wcm94eS5jaGVnZy5jb20vbW9iaWxlLXN0dWR5LWJmZi9ncmFwaHFsLw==&h=UE9TVA==';
    var script = document.createElement('script');
    script.src = pxCaptchaSrc;
    script.onload = onScriptLoad;
    script.onerror = onScriptError;
    var onScriptErrorCalled;
    document.head.appendChild(script);
    var timeoutID = setTimeout(onScriptError, 5000);
    function onScriptLoad() {
        clearTimeout(timeoutID);
        setTimeout(function() {
            if (!isContentLoaded()) {
                onScriptError();
            }
        }, 2500);
    }
    function onScriptError() {
        if (onScriptErrorCalled) {
            return;
        }
        onScriptErrorCalled = true;
        script = document.createElement('script');
        script.src = 'https://captcha.px-cloud.net/PXaOtQIWNf/captcha.js?a=c&u=dd97996f-742d-11ef-b4ae-3f85b5657c5a&v=&m=0&b=aHR0cHM6Ly9wcm94eS5jaGVnZy5jb20vbW9iaWxlLXN0dWR5LWJmZi9ncmFwaHFsLw==&h=UE9TVA==';
        script.onload = function() {
            clearTimeout(timeoutID);
        };
        script.onerror = window._pxOnError;
        document.head.appendChild(script);
        timeoutID = setTimeout(function() {
            if (!isContentLoaded()) {
                window._pxOnError();
            }
        }, 5000);
    }
    function isContentLoaded() {
        return !!document.querySelector('div,span');
    }
    window._pxOnError = function () {
        var style = document.createElement('style');
        style.innerText = '@import url(https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap);body{background-color:#fafbfc}.px-captcha-error-container{position:fixed;height:340px;background-color:#fff;font-family:Roboto,sans-serif}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:67px 0 33px;font-weight:500;line-height:.83;text-align:center}.px-captcha-error-message{color:#f0f1f2;font-size:18px;margin:0 0 29px;line-height:1.33;text-align:center}.px-captcha-error-button{text-align:center;line-height:48px;width:253px;margin:auto;border-radius:50px;border:solid 1px #f0f1f2;font-size:20px;color:#f0f1f2}.px-captcha-error-wrapper{margin:18px 0 0}div.px-captcha-error{margin:auto;text-align:center;width:400px;height:30px;font-size:12px;background-color:#fcf0f2;color:#ce0e2d}img.px-captcha-error{margin:6px 8px -2px 0}.px-captcha-error-refid{border-top:solid 1px #f0eeee;height:27px;margin:13px 0 0;border-radius:0 0 3px 3px;background-color:#fafbfc;font-size:10px;line-height:2.5;text-align:center;color:#b1b5b8}@media (min-width:620px){.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (min-width:481px) and (max-width:620px){.px-captcha-error-container{width:85%;top:50%;left:50%;margin-top:-170px;margin-left:-42.5%;border-radius:3px;box-shadow:0 2px 9px -1px rgba(0,0,0,.13)}}@media (max-width:480px){body{background-color:#fff}.px-captcha-error-header{color:#f0f1f2;font-size:29px;margin:55px 0 33px}.px-captcha-error-container{width:530px;top:50%;left:50%;margin-top:-170px;margin-left:-265px}.px-captcha-error-refid{position:fixed;width:100%;left:0;bottom:0;border-radius:0;font-size:14px;line-height:2}}@media (max-width:390px){div.px-captcha-error{font-size:10px}.px-captcha-error-refid{font-size:11px;line-height:2.5}}';
        document.head.appendChild(style);
        var div = document.createElement('div');
        div.className = 'px-captcha-error-container';
        div.innerHTML = '<div class="px-captcha-error-header">Before we continue...</div><div class="px-captcha-error-message">Press & Hold to confirm you are<br>a human (and not a bot).</div><div class="px-captcha-error-button">Press & Hold</div><div class="px-captcha-error-wrapper"><div class="px-captcha-error"><img class="px-captcha-error" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAAQCAMAAADDGrRQAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAABFUExURUdwTNYELOEGONQILd0AONwALtwEL+AAL9MFLfkJSNQGLdMJLdQJLdQGLdQKLtYFLNcELdUGLdcBL9gFL88OLdUFLNEOLglBhT4AAAAXdFJOUwC8CqgNIRgRoAS1dWWuR4RTjzgryZpYblfkcAAAAI9JREFUGNNdj+sWhCAIhAdvqGVa1r7/oy6RZ7eaH3D4ZACBIed9wlOOMtUnSrEmZ6cHa9YAIfsbCkWrdpi/c50Bk2CO9mNLdMAu03wJA3HpEnfpxbyOg6ruyx8JJi6KNstnslp1dbPd9GnqmuYq7mmcv1zjnbQw8cV0xzkqo+fX1zkjUOO7wnrInUTxJiruC3vtBNRoQQn2AAAAAElFTkSuQmCC">Please check your internet connection' + (window._pxMobile ? '' : ' or disable your ad-blocker') + '.</div></div><div class="px-captcha-error-refid">Reference ID ' + window._pxUuid + '</div>';
        document.body.appendChild(div);
        if (window._pxMobile) {
            setTimeout(function() {
                location.href = '/px/captcha_close?status=-1';
            }, 5000);
        }
    };
</script>

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions