无法验证我对特定网站的查询

Unable to validate my query for particular website

我正在尝试查询以下内容website

其中 Access Number 将是 8778791867

的固定值

PIN 将是 dynamic

从普通浏览器我可以检查它是有效还是无效pin

但是使用下面的代码,我无法获得浏览器获得的准确答案。因为我一直对所有条目无效!

import httpx
import trio
import sys
import re
from bs4 import BeautifulSoup
from termcolor import colored
import os

# proxies = {
#     'https': 'http://127.0.0.1:8866'
# }


async def GetValues(client):
    r = await client.get(baseurl)
    soup = BeautifulSoup(r.text, 'lxml')
    return soup.select_one(
        '#__VIEWSTATE')['value'], soup.select_one('#__EVENTVALIDATION')['value']


async def GetToken(client):
    headers = {
        'Content-Type': 'application/x-protobuffer'
    }
    data = "\n\u0018qc5B-qjP0QEimFYUxcpWJy5B\u0012Ž\u000b03AGdBq264NJCBRJatpe-BlWUNra15cx9i1vtKgAz1cUbsPDMuuhHWpUB1CYdgH3nbhMONc8_uOtU1T3h5hIL0CplyaAt579wUhKd8UshQxTG9L-WRv1W1kNXu8iSF8MzlBxLjrySrHXux6eOm8HG9-oSmdonrvCgv4hkCK43XX_I3leXuhALavOAM06BR-3jYT1Kp0P0OiF8NMyswLsDS9jJUJ-2-290TrTwkuVCEB5YfuJxOvpemh_9iNkmGKRjCbzt5pPoTU_YOp0x2ycmYPNPpPsO9hL35FMiZys6y65q4ynZawQyNYIrAHp4cxAD8Pgj6YmS6Q_cGDTvLsKX60ZeV_W88uWjOC9rTcMHVvpBhbaAukM7p1T2hobQ94fYs1Dabk5LFdRkGUMg-QzWV5OSTXcc-zk7WBQPnF9e4uF2ii3gK1neLoQibb0453SwOp-2PWNbxbjA-nNvj8I-n5ePBV7dkM3P_31E7SOrycN04Wymy5rrV_nX74hLIDBoFph1BOE5aV8f4qu7wHquyPei4Vuq_QoTtLKhmwmSh4xP5-qbrB_N8azx8RTO9EJbMBmgh5FLgqhS4AG-M1YXrsjnSeYmJwXggl7wuvHfkjdzEKXKVdC1egfjC8T-HO-LWozjuDxFmNSioZYjV21JBsWW2DXN5H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_Oe8dfyZIoK8CYdsG5hMcObuvd9WaNQ8vj49F_8tx_AyUz6SJCy_r1rV5oDVjTZetmICz1mmk8vQzC6kf7Hwm0ZbmxoxGmj-VsviyYTS1dVgEvdnwpUf2m8j-zC3CQTmHHmDu12EJXO4qh5bq4_EFkIdJiUu_IdrEbwaLNC0GL1MqPcTySypXmoS-HSqNdncg0GJ4Zprs_yYsfbpHB9Oj0cv2epDjFPvwYOpwmWPC9Vb7dJcyvXCsmugeEEgmh7Rb6aS1IJ1DCs4nfHUYZ_Gx8_aBi-GL4Zyh3V2sk_GhpBHXjDCsZ7e5_NIJTHHKHjMsjq2RzOYwjVZPMNs36WyDWLbxUltL01ix7ye8XFUR-xmO2gk_JZ40po4O04-PDxLJv1SVsLOnCgyKKZBehzRTHgsDslXT2_eU0QIoVQ7nb3Tj44z0VUjdegWaoNJXp3OUwGY2MNoogzgbS9M0fn6Qop9vaEQKJGhjUn33rhIKOc9MpvDkiWwcAisxu9o-UH1OMs9Y-9EQF35TzhsMauE4G3L2so-yKdtKL-N8y728V-xXHBXnA2pzdj66bdsgubhcpPgqXGPKV05U6IX7z61VkltXoUnxtQqzXCjk1sK1EVIy3WlNisMB0TJgmZxusfIFhIRLfiks0og4lEDuTFOfqW1nBc4uja3Ud89kEYvygvDvQY6Iy4IDQYDKWiP7hP8r5XyckWdA3a3zqPg8Rx_XWSwRTPmeyV8qcgaH0YAab4pkCEYytcrZqF8GtWFa5_-deX1kjqRHbp__m-QwajI3N5N6ow4WprUojCZlDi3tIdYlN5hE19NlIyNMqybERrzG29eo7SFuRRa14Wjx5Y7zGE9Pd-gHpJ0dl2fjJ_3RtgStu*\n-7587942622\u0001qB\bRecharger(6Le8DfAUAAAAAKsECBdLJ0Z_I7TlcVufkB2QdCCi"
    r = await client.post(
        'https://www.google.com/recaptcha/api2/reload?k=6Le8DfAUAAAAAKsECBdLJ0Z_I7TlcVufkB2QdCCi', data=data.encode('latin-1'), headers=headers)
    return re.search('"(\d.*?)"', r.text).group(1)


async def main(numbers, baseurl):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0"
    }
    # async with httpx.AsyncClient(timeout=None, headers=headers, proxies=proxies, verify=False) as client, trio.open_nursery() as nurse:
    async with httpx.AsyncClient(timeout=None, headers=headers) as client, trio.open_nursery() as nurse:
        async def check(num):
            values = await GetValues(client)
            # token = await GetToken(client)
            data = {
                "ctl00$masterScriptManager": "ctl00$attContent$ctl00|ctl00$attContent$btnSubmit",
                "__EVENTTARGET": "",
                "__EVENTARGUMENT": "",
                "__VIEWSTATE": values[0],
                "__VIEWSTATEGENERATOR": "C5057F25",
                "__EVENTVALIDATION": values[1],
                "ctl00$attContent$txtAccessNumber": "8778791867",
                "ctl00$attContent$txtPIN": num,
                "ctl00$attContent$hdnTier": "",
                # "ctl00$attContent$hdnTokenRecharge": token,
                "ctl00$EmailSignup$txtEmailSignup": "",
                "ctl00$hfUserId": "",
                "__ASYNCPOST": "true",
                "ctl00$attContent$btnSubmit": "Submit"
            }
            r = await client.post(baseurl, data=data)

            if 'Invalid' in r.text:
                print(f"Num: {num}, Status: {colored('Invalid','red')}")
            else:
                print(f"Num: {num}, Status: {colored('Valid','green')}")

        for num in numbers:
            nurse.start_soon(check, num)


if __name__ == "__main__":
    baseurl = 'https://www.virtualprepaidminutes.com/ATT_prepaid_calling_cards_refill_online.aspx'
    numbers = [5418531366, 5418531367]
    trio.run(main, numbers, baseurl)
    
    # if len(sys.argv) == 2:
    #     try:
    #         with open(sys.argv[1]) as f:
    #             numbers = f.read().splitlines()
    #         trio.run(main, numbers, baseurl)
    #     except FileNotFoundError as e:
    #         print(f"File {e.filename} is not exist!")
    # else:
    #     print(f"Usage: python {os.path.basename(__file__)} `InputFile`")

它应该 return 对 5418531366 无效并且对 5418531367

有效

但出于某种原因我对这两个数字都无效:

The following response is the actual HTML response.


提前致谢。

我想用 selenium 处理它。因为我也为此任务构建了一个 selenium 脚本。

您尝试自动化的站点已将 google 的 reCAPTCHA v3 集成到其表单中:

 <script src="https://www.google.com/recaptcha/api.js?render=6Le8DfAUAAAAAKsECBdLJ0Z_I7TlcVufkB2QdCCi"></script></style>

这是网络抓取工具和自动化脚本的已知问题。由于验证码的服务器端验证失败并将您的脚本检测为机器人,即使提交有效,您也变得无效的原因。

reCAPTCHA described by google 为:

reCAPTCHA uses an advanced risk analysis engine and adaptive challenges to keep malicious software from engaging in abusive activities on your website. Meanwhile, legitimate users will be able to login, make purchases, view pages, or create accounts and fake users will be blocked.

你似乎在 GetToken 函数中试图绕过它,但显然失败了,我建议你阅读更多关于 reCAPTCHA 的信息以了解原因。请参阅有关 reCAPTCHA here and this Whosebug answer.

的官方 google 文档

这里没有任何人可以为您提供解决方法,有提供验证码解决服务的在线付费服务。就我个人而言,我从来不需要使用此类服务​​,但您可以 google 为他们服务。