AmmeySaini / Chegg-Answer-Bot

You can share your Chegg account for answers using this bot with your friends without getting your account blocked/flagged
MIT License
50 stars 29 forks source link

Captcha Appeared #34

Open Faizan-26 opened 3 days ago

Faizan-26 commented 3 days ago

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 

       `

<!DOCTYPE html>

Access to this page has been denied

`

Faizan-26 commented 3 days ago

Is there anyway to solve this issue